Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# windows应用商店应用程序xaml模板属性_C#_Wpf_Xaml_Windows Store Apps - Fatal编程技术网

C# windows应用商店应用程序xaml模板属性

C# windows应用商店应用程序xaml模板属性,c#,wpf,xaml,windows-store-apps,C#,Wpf,Xaml,Windows Store Apps,我已经定义了自定义ListviewItemStyle。 在样式模板中有一个按钮 <Button x:Name="btnAbout" Grid.Column="1" Style="{StaticResource GCAboutButton}" Visibility="Collapsed" Command="{Binding DataContext.AboutCommand, ElementName=List}" Co

我已经定义了自定义
ListviewItemStyle
。 在样式模板中有一个按钮

<Button x:Name="btnAbout"  Grid.Column="1"
        Style="{StaticResource GCAboutButton}"
        Visibility="Collapsed"     
        Command="{Binding DataContext.AboutCommand, ElementName=List}"
        CommandParameter="{Binding Item}">
</Button>
问题是: 当
SelectedItem
为男性时,按钮必须可见;当所选项目为女性时,按钮必须不可见。
如何从代码中访问模板中定义的按钮。例如,在
列表视图的
事件中,您可以使用implicit数据模板。看到这一点,也可能会有所帮助。

DataTemplate类的DataType属性与Style类的TargetType属性非常相似,因此可以根据您的类型管理该模板。

必须在
可见性
属性上使用数据绑定。为此,您可能需要定义一个转换器。为男性和女性定义两个新的可视状态。在这些可视化状态中,更改按钮的可见性。从SelectionChanged事件中应用适当的VisualState。@VictoryJessie Visual State是ViewElement的一个参数。如何获取列表框的选定视图?我可以获取选定的绑定项,但不能获取视图。请使用GetTemplateChild(string childName)方法从模板获取按钮@VictoryJessie您误解了,我如何才能获得ListViewItem的模板,即已选中?
class Base; class Man: Base; class Woman:Base;