0

Im creating a few buttons in code behind.

List<Button> steps = new List<Button>();
Steps.Add(new Button
{
Style = (System.Windows.Style)Application.Current.TryFindResource("WorkflowButtonStyle")  
,Content = StepDescription                    
, Command = WfCommand
, CommandParameter = workflowToFrom                                             
, Width = 206 
});

The style always returns as null. I even tried to load a resource dictionary.

Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/Resources;component/Dictionaries/FormD.xaml", UriKind.Relative)) as ResourceDictionary);

and still doesnt load the style. The dictionary exists in another project..it works when i reference it in the XAML. But doesnt seem to like it in the code behind. Anybody face the same issue?

dymanoid
  • 14,771
  • 4
  • 36
  • 64

1 Answers1

0
List<Button> steps = new List<Button>();
Steps.Add(new Button
{
Content = Description                    
, Command = WfCommand
, CommandParameter = ToFrom                                             
, Width = 200 
});

and I set some values in the resource dictionary shown below-

 <Style x:Key="ButtonStyle">
        <Setter Property="Button.Margin" Value="4"/>
        <Setter Property="Button.MinWidth" Value="75"/>
        <Setter Property="Button.HorizontalAlignment" Value="Left"/>
    </Style>

and the call for including the buttons generated in the code is-

<ItemsControl ItemsSource="{Binding Steps}" VerticalAlignment="Bottom" Style="{StaticResource ButtonStyle}">                               
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel FlowDirection="LeftToRight" HorizontalAlignment="Stretch" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                </ItemsControl>