2011-05-06 93 views
1

我有一个用silverlight(非wp7)创建的用户控件。 我在WP7应用程序中使用此控件,它工作。我唯一的问题是,控件的风格与应用风格不匹配(它的背景是白色,文本框与文本框的颜色相同,因此不显示等)。 我可以将应用程序样式设置为XAML中的用户控件吗?在Silverlight中添加样式Silverlight用户控件silverlight

这是用户控件的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控件,你可以为Silverlight/WPF。如果没有看到有关的XAML,就不可能给你一个可行的解决方案,但方法是一样的。

如果您需要更多帮助,请发布控件的XAML并突出显示与您希望它们不同的区域。

UPDATE:你应该使用UserControl使用Control切换,而不是让你可以创建一个“无外观的”控件,具有限定在generic.xaml外观的控制tempalte。然后,您可以使用Background="{TemplateBinding Background}"模板绑定到控件上的依赖项属性(Background和Foreground已在Control上定义)。在无形的控制上有一些很棒的资源,ege。 http://channel9.msdn.com/blogs/jbienz/creating-lookless-controls-for-wpf-and-silverlight

+0

谢谢,我添加了xaml – Ido 2011-05-06 12:27:28