c# - WPF 将控件的 zindex 绑定(bind)到属性不起作用

标签 c# .net wpf xaml

如果我将一个控件的 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/

相关文章:

c# - 比较两个列表的最快方法

wpf - 在两个相同的应用程序之间进行锣拖放

WPF-如何将用户控件放置在AdornedElementPlaceholder上?

c# - 将 WinForm ContextMenu 背景设为灰色?

c# - 为什么我无法再反序列化这些数据?

c# - 散列 Json 结果以检测变化

c# - Process.Kill() 和进程事件

c# 在数据库中存储用户设置

wpf - 为什么 ListCollectionView.CustomSort 这么慢?

C# Modbus/tcp - 挂起连接