Jan*_*vil 8 wpf xaml styles windows-phone-7
A有一个ListBox项,每个ListBoxItem都包含一个Path对象形式的图标,如下所示:
<ListBox.ItemTemplate>
<DataTemplate>
<Grid ...>
...
<Path Margin="4" Style="{StaticResource ErrorIconPath}"
Stretch="Uniform" Width="26" Height="26"
RenderTransformOrigin="0.5,0.5" Grid.Column="1" Grid.Row="1"
UseLayoutRounding="False"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
Path的样式包含在Appl.xaml(Application.Resourcessection)中,如下所示:
<Style x:Key="ErrorIconPath" TargetType="Path">
<Setter Property="Data" Value="F1M874.094,289.369L854.3,254.63C854.028,254.151 853.515,253.856 852.958,253.856 852.403,253.856 851.89,254.151 851.617,254.63L831.824,289.369C831.555,289.84 831.559,290.416 831.835,290.883 832.111,291.348 832.618,291.634 833.165,291.634L872.752,291.634C873.299,291.634 873.805,291.348 874.081,290.883 874.357,290.416 874.361,289.84 874.094,289.369 M855.653,287.189L850.264,287.189 850.264,282.745 855.653,282.745 855.653,287.189z M855.653,279.41L850.264,279.41 850.264,266.077 855.653,266.077 855.653,279.41z" />
</Style>
Run Code Online (Sandbox Code Playgroud)
问题是只有ListBox中的第一个项目Data按预期绑定属性,其他项目根本没有绑定它(因此它们显示为空格,但匹配的大小Path).此外,当我在其他任何地方(即ListBox之外)使用样式时,只会发生第一个发生的实例.
奇怪的是,如果我在内联中定义Fill属性Style而不是内联,它可以正常工作并且不会出现与Path属性相同的问题.
我的猜测是,这与Data不是原始类型有关,但我没有找到任何修复.
编辑:有趣的是,当我将Data属性直接绑定到System.String资源时,它的工作原理.我仍然希望能够通过Style定义此属性.
编辑2:我在WPF中遇到了同样的问题,当通过更多按钮使用的样式设置按钮内容的路径时.该路径仅显示一个按钮,其他按钮为空白.
Path.Fill是DependencyProperty,而Path.Data则不是.相反:
<DataTemplate>
<Grid ...>
...
<ContentPresenter Content="{StaticResource MyPath}"/>
</Grid>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
ContentPresenter.Content 是一个DependencyProperty所以这应该工作:
<Path x:Key="MyPath" Margin="4" Style="{StaticResource ErrorIconPath}"
Stretch="Uniform" Width="26" Height="26" VerticalAlignment="Center"
RenderTransformOrigin="0.5,0.5" Grid.Column="1" Grid.Row="1"
UseLayoutRounding="False" HorizontalAlignment="Center"
Data="F1M874.094,289.369L854.3,254.63C854.028,254.151 853.515,253.856 852.958,253.856 852.403,253.856 851.89,254.151 851.617,254.63L831.824,289.369C831.555,289.84 831.559,290.416 831.835,290.883 832.111,291.348 832.618,291.634 833.165,291.634L872.752,291.634C873.299,291.634 873.805,291.348 874.081,290.883 874.357,290.416 874.361,289.84 874.094,289.369 M855.653,287.189L850.264,287.189 850.264,282.745 855.653,282.745 855.653,287.189z M855.653,279.41L850.264,279.41 850.264,266.077 855.653,266.077 855.653,279.41z"/>
Run Code Online (Sandbox Code Playgroud)
我猜几何不能共享。您是否尝试过将其设置为:x:Shared= "false"
<Style x:Key="ErrorIconPath" TargetType="Path">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1949 次 |
| 最近记录: |