如果我将一个控件的 ZIndex 绑定(bind)到一个属性,虽然我在调试时明确调用了该属性(断点在 getter 上),但 zindex 似乎不起作用(即 zindex 在正确运行的应用程序;如果我将 zindex 设置为绑定(bind)到属性而不是 XAML 中的设置值,则控件上的元素不再可单击)。 知道为什么,或者如何解决这个问题吗?感谢您的帮助!
<views:LaunchableApplicationControl BorderThickness="0"
BorderBrush="DarkSlateGray" x:Name="LaunchableApplicationControl"
Grid.Column="1" Margin="25,150,25,50"
Panel.ZIndex="{Binding LaunchableControlZIndex}"
Grid.Row="0" Grid.RowSpan="2"
DataContext="{Binding LaunchableApplication, Mode=OneWay,
Source={StaticResource Locator}}"/>
最佳答案
您可以尝试 DataContext="{Binding ElementName=LaunchableApplicationControl}"
并绑定(bind)到将设置 ZIndex
的属性。确保您实现了 INotifyPropertyChanged
interface
。
private int _Zindex;
public int Zindex
{
get { return _Zindex; }
set
{
if (_Zindex == value)
{
return;
}
_Zindex = value;
NotifyPropertyChanged("Zindex");
}
}
关于c# - WPF 将控件的 zindex 绑定(bind)到属性不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36913049/