我有自定义用户控件的gridview。 这是usercontrol的XAML:
<UserControl
x:Class="App11.VideoPreview"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App11"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="250"
d:DesignWidth="250">
<Grid>
<Button Height="250" Width="250" Padding="0" BorderThickness="0">
<StackPanel>
<Image Name="image1" Height="250" Width="250" Stretch="None"/>
<Grid Margin="0,-74,0,0">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" Opacity="0.5">
<GradientStop Color="Black"/>
<GradientStop Color="#FF5B5B5B" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<TextBlock x:Name="textBox1" TextWrapping="Wrap" FlowDirection="RightToLeft" Foreground="White" Padding="5"/>
</Grid>
</StackPanel>
</Button>
</Grid>
</UserControl>
如何在gridview中单击按钮时捕获click事件?
我在gridview页面的.cs中尝试了GridView_ItemClick
,GridView1_SelectionChanged
我还在usercontrol页面的.cs中尝试了button_Click
两者都不适合我。知道为什么吗?
编辑:
它确实有效。我只是尝试使用Frame.Navigate(typeof(PageName));
更改框架
我无法从usercontrol更改帧,我必须将当前帧发送到构建函数中的usercontrol,然后更改框架,如下所示:
Frame frame;
public VideoPreview(Frame f)
{
this.InitializeComponent();
frame = f;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
frame.Navigate(typeof(PlayVideo));
}
答案 0 :(得分:0)
尝试研究MVVM模式http://www.codeproject.com/Articles/165368/WPF-MVVM-Quick-Start-Tutorial并使用命令而不是事件。
<Button Command="{Binding SomeActionCommand}" />
这将使您的代码更加清晰和可靠。