在#WPF中你有ItemTemplateSelectors。但是,您是否还可以根据绑定对象的数据类型选择ItemContainerStyle?
我正在对散点图进行数据绑定。我想根据DataContext中的对象设置生成的ScatterViewItems的一些属性。对于样式,类似于ItemTemplateSelector的机制会很棒。那可能吗?我现在绑定到我正在显示的对象中的属性以获得效果,但这感觉就像开销和太复杂(最重要的是,我们的XU设计师不能自己做的事情)。
这是我现在使用的XAML。非常感谢您的帮助。
<s:ScatterView x:Name="topicsViewer">
<s:ScatterView.ItemTemplateSelector>
<local:TopicViewerDataTemplateSelector>
<DataTemplate DataType="{x:Type mvc:S7VideoTopic}">
<Grid>
<ContentPresenter Content="{Binding MediaElement}" />
<s:SurfaceButton Visibility="{Binding MailToVisible}" x:Name="mailto" Tag="{Binding Titel}" Click="mailto_Click" HorizontalAlignment="Right" VerticalAlignment="Top" Background="Transparent" Width="62" Height="36">
<Image Source="/Resources/MailTo.png" />
</s:SurfaceButton>
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center" Height="32">
<s:SurfaceButton Tag="{Binding MediaElement}" x:Name="btnPlay" Click="btnPlay_Click">
<Image Source="/Resources/control_play.png" />
</s:SurfaceButton>
<s:SurfaceButton Tag="{Binding MediaElement}" x:Name="btnPause" Click="btnPause_Click">
<Image Source="/Resources/control_pause.png" />
</s:SurfaceButton>
<s:SurfaceButton Tag="{Binding MediaElement}" x:Name="btnStop" Click="btnStop_Click">
<Image Source="/Resources/control_stop.png" />
</s:SurfaceButton>
</StackPanel>
</Grid>
</DataTemplate>
<DataTemplate DataType="{x:Type mvc:S7ImageTopic}">
<Grid>
<ContentPresenter Content="{Binding Resource}" />
<s:SurfaceButton Visibility="{Binding MailToVisible}" x:Name="mailto" Tag="{Binding Titel}" Click="mailto_Click" HorizontalAlignment="Right" VerticalAlignment="Top" Background="Transparent" Width="62" Height="36">
<Image Source="/Resources/MailTo.png" />
</s:SurfaceButton>
</Grid>
</DataTemplate>
<DataTemplate DataType="{x:Type local:Kassa}">
<ContentPresenter Content="{Binding}" Width="300" Height="355" />
</DataTemplate>
</local:TopicViewerDataTemplateSelector>
</s:ScatterView.ItemTemplateSelector>
<s:ScatterView.ItemContainerStyle>
<Style TargetType="s:ScatterViewItem">
<Setter Property="MinWidth" Value="200" />
<Setter Property="MinHeight" Value="150" />
<Setter Property="MaxWidth" Value="800" />
<Setter Property="MaxHeight" Value="700" />
<Setter Property="Width" Value="{Binding DefaultWidth}" />
<Setter Property="Height" Value="{Binding DefaultHeight}" />
<Setter Property="s:ScatterViewItem.CanMove" Value="{Binding CanMove}" />
<Setter Property="s:ScatterViewItem.CanScale" Value="{Binding CanScale}" />
<Setter Property="s:ScatterViewItem.CanRotate" Value="{Binding CanRotate}" />
<Setter Property="Background" Value="Transparent" />
</Style>
</s:ScatterView.ItemContainerStyle>
</s:ScatterView>
Bart Roozendaal,Sevensteps
答案 0 :(得分:1)
如何使用ItemContainerStyleSelector(呃!)...抱歉,这是一个漫长的夜晚