2014-12-17 1 views
0

코드 뒤에 몇 개의 버튼을 만듭니다.버튼을 만드는 동안 코드 파일에서 리소스 파일의 스타일을로드 할 수 없습니다.

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 
}); 

스타일은 항상 null로 반환됩니다. 리소스 딕셔너리를로드하려고했습니다.

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

여전히 스타일을로드하지 않습니다. 사전은 다른 프로젝트에 있습니다. 내가 XAML에서 참조 할 때 작동합니다. 하지만 나던데 코드 뒤에 그것을 좋아하는 것. 누구도 같은 문제에 직면 해 있습니까?

답변

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

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

below- 도시 리소스 사전에 어떤 값을 설정하는 코드 생성 버튼을 포함한 호출

<ItemsControl ItemsSource="{Binding Steps}" VerticalAlignment="Bottom" Style="{StaticResource ButtonStyle}">        
        <ItemsControl.ItemsPanel> 
         <ItemsPanelTemplate> 
          <StackPanel FlowDirection="LeftToRight" HorizontalAlignment="Stretch" /> 
         </ItemsPanelTemplate> 
        </ItemsControl.ItemsPanel> 
       </ItemsControl> 
을 인걸요
관련 문제