C# 在DependencyProperty中使用数据绑定
我创建了一个从C# 在DependencyProperty中使用数据绑定,c#,wpf,xaml,data-binding,dependency-properties,C#,Wpf,Xaml,Data Binding,Dependency Properties,我创建了一个从Window继承的类,它有一个名为TitlebarContent的DependencyProperty 公共框架元素标题栏内容 { get{return(FrameworkElement)GetValue(TitleBarContentProperty);} set{SetValue(TitleBarContentProperty,value);} } //使用DependencyProperty作为标题栏内容的后备存储。这将启用动画、样式、绑定等。。。 公共静态只读从属属性Tit
Window
继承的类,它有一个名为TitlebarContent的DependencyProperty
公共框架元素标题栏内容
{
get{return(FrameworkElement)GetValue(TitleBarContentProperty);}
set{SetValue(TitleBarContentProperty,value);}
}
//使用DependencyProperty作为标题栏内容的后备存储。这将启用动画、样式、绑定等。。。
公共静态只读从属属性TitleBarContentProperty=
DependencyProperty.Register(“TitleBarContent”、typeof(FrameworkElement)、typeof(tkWindowControl)、new PropertyMetadata(default(FrameworkElement));
在样式的ResourceDictionary
中,我为该属性添加了ContentControl
。
现在我想在另一个应用程序中使用新的“WindowObject”,并访问新的标题BarContentProperty
。我可以看到标题栏中的项目,并且可以移动窗口
,调整大小等等。但我无法绑定到这些项目。例如,我想在标题栏中添加一个帮助按钮。显示了按钮
,但我无法单击它
我的dependencProperty
是类型的(FrameWorkElement)
,因为我喜欢在标题栏中添加几个按钮
可以这样使用我的绑定吗?将按钮或父元素的WindowChrome.ishitestvisibleinchrome
附加属性设置为true
:
<Button Content="Exit" WindowChrome.IsHitTestVisibleInChrome="True" ... />
或者,您应该减小WindowChrome
的CaptionHeight
属性的值,如果您的按钮显示在UI中,那么我希望您所需要做的就是在窗口的数据上下文中有一个公共iCommand属性ExitApplicationCommand。你现在有什么?背景已经做好了。我把按钮放在一个普通的格子里,试着装订。一切正常。但是在标题栏内容中使用的按钮没有IsMouseOver
效果,绑定不再起作用。您再次帮助我@mm8。现在我的UI已经完成了。非常感谢。