2011-05-06 6 views
1

실버 라이트 (비 wp7)로 만든 사용자 콘트롤이 있습니다. WP7 앱에서이 컨트롤을 사용하고 있습니다. 내 유일한 문제는 컨트롤의 스타일이 app 스타일과 일치하지 않는다는 것입니다 (배경이 흰색이고 텍스트 상자가 텍스트 상자 색과 같지 않으므로 표시되지 않습니다 '등). XAML에서 사용자 정의 컨트롤에 앱 스타일을 설정할 수 있습니까?실버 라이트에서 실버 라이트 사용자 컨트롤에 스타일 추가하기

이것은 사용자 정의 컨트롤의 XAML입니다. 내 자신의 색상 (투명, 배경색은 검은 색, 전경색은 흰색)을 사용했습니다. 나는 컨트롤 안에있는 색을 사용하고 싶지 않습니다, 나는이 컨트롤을 포함하는 wp7 컨트롤에서 그들을 얻고 싶습니다.

WP7 :

<commonWpControls:MyUserControls x:Name="myControl" DataContext="{Binding MyViewModel}" /> 

사용자 제어 :

<Grid x:Name="LayoutRoot" Background="Transparent" VerticalAlignment="Stretch" > 
    <StackPanel VerticalAlignment="Stretch"> 
     <StackPanel Orientation="Horizontal"> 
      <TextBlock x:Name="nameBlock" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Text="Name:" Foreground="White" /> 
      <TextBox x:Name="nameTextBox" Grid.Row="0" Grid.Column="1" Text="{Binding Path=Name}" Background="Black" Foreground="White" /> 
     </StackPanel> 
     <StackPanel Grid.Row="3" Grid.Column="1" Background="Black" VerticalAlignment="Stretch" > 
       <ListBox Margin="12,12,0,0" Name="listBox1" ItemsSource="{Binding Path=PropertiesCollection}" Background="Transparent" VerticalAlignment="Stretch" > 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
          <Grid> 
           <Grid.ColumnDefinitions> 
            <ColumnDefinition Width="100"></ColumnDefinition> 
            <ColumnDefinition Width="*"></ColumnDefinition> 
           </Grid.ColumnDefinitions> 
           <TextBlock Text="{Binding Key}" VerticalAlignment="Center" Grid.Column="0" Foreground="White"/> 
           <TextBox Text="{Binding Value, Mode=TwoWay}" Grid.Column="1" Background="Black" Foreground="White"/> 
          </Grid> 
         </DataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox> 
     </StackPanel> 

    </StackPanel> 
</Grid> 

답변

1

당신은 정확히 같은 방식으로 WP7의 컨트롤 스타일을 지정할 수 있습니다 당신이 할 수있는 실버 라이트/WPF합니다. 문제의 XAML을 보지 않고도 작업 솔루션을 제공하는 것은 불가능하지만 접근 방법은 동일합니다.

도움이 더 필요하면 컨트롤에 대한 XAML을 게시하고 원하지 않는 영역을 강조 표시하십시오.

UPDATE : 당신이 generic.xaml을의 모양을 정의하는 제어 tempalte이있는 "lookless"컨트롤을 만들 수 있습니다 대신 있도록 Control를 사용하여 UserControl를 사용하여 전환해야한다. 그런 다음 Background="{TemplateBinding Background}" 템플릿을 컨트롤의 종속성 속성에 바인딩 할 수 있습니다 (Background 및 Foreground는 이미 Control에 정의되어 있습니다). 보이지 않는 컨트롤에는 훌륭한 리소스가 있습니다. http://channel9.msdn.com/blogs/jbienz/creating-lookless-controls-for-wpf-and-silverlight

+0

감사합니다. xaml을 추가했습니다. – Ido