C# 使WPF文本块不可单击
我有一个简单的用户控件,带有一个文本块和两个按钮C# 使WPF文本块不可单击,c#,wpf,xaml,C#,Wpf,Xaml,我有一个简单的用户控件,带有一个文本块和两个按钮 <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="150" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDe
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Height="30" Text="Please install updates" Foreground="#FFF" FontWeight="Bold" Margin="0,0,0,20" Grid.RowSpan="2"/>
<Button Grid.Column="0" Grid.Row="1" Content="Restart Now" Margin="5 0 0 0" Width="80" Height="25" HorizontalAlignment="Right" />
<Button Grid.Column="1" Grid.Row="1" Content="Snooze" Width="60" Height="25" Margin="10 0 0 0" HorizontalAlignment="Left" Click="bttnOK_Click" />
</Grid>
由于某些原因,TextBlock是可单击的,当您单击它时,它会关闭控件。
所需行为:不可单击的文本块。单击TextBlock时,控件保持打开状态。您似乎添加了
,这使TextBlock进入按钮区域。
或者,如果删除TextBlock中的行跨度无法解决问题,请尝试将ishitestvisible=false
添加到TextBlock
看起来是这样的,
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Height="30" Text="Please install updates" Foreground="#FFF" FontWeight="Bold" Margin="0,0,0,20"/>
<Button Grid.Column="0" Grid.Row="1" Content="Restart Now" Margin="5 0 0 0" Width="80" Height="25" HorizontalAlignment="Right" />
<Button Grid.Column="1" Grid.Row="1" Content="Snooze" Width="60" Height="25" Margin="10 0 0 0" HorizontalAlignment="Left" Click="bttnOK_Click" />
通常它们是不可点击的。也许您有一个覆盖默认属性的样式?它将
IsCancel
设置为true
。您能提供有关父对象/样式的更多详细信息吗?我刚刚将您的XAML复制到一个全新的项目中,文本块
不可单击。问题一定出在其他地方。此用户控件位于telerik DesktopAlert内,可能这就是导致问题的原因。即使RowSpan=2,按钮仍位于文本块的顶部。那么重点是什么呢?从视觉上看,它们是…,但可能是按钮边框已经扩展到了文本块。或者,您封装此UserControl的容器是可单击的。尝试将IshittesVisible=false添加到容器中。IshittesVisible=“false”帮助。谢谢!