【发布时间】:2019-09-07 11:06:05
【问题描述】:
我创建了一个继承自Window 的类,并有一个名为TitlebarContent 的DependencyProperty。
public FrameworkElement TitleBarContent
{
get { return (FrameworkElement)GetValue(TitleBarContentProperty); }
set { SetValue(TitleBarContentProperty, value); }
}
// Using a DependencyProperty as the backing store for TitleBarContent. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TitleBarContentProperty =
DependencyProperty.Register("TitleBarContent", typeof(FrameworkElement), typeof(tkWindowControl), new PropertyMetadata(default(FrameworkElement)));
在样式的ResourceDictionary 中,我为此属性添加了ContentControl。
现在我想在另一个应用程序中使用新的“WindowObject”并访问新的TitlebarContentProperty。我可以看到标题栏中的项目,我可以移动Window,调整它的大小等等。但我无法绑定到这些项目。例如,我想在标题栏中添加一个帮助按钮。 Button 已显示,但我无法单击它。
<tk:tkWindowControl.TitleBarContent>
<DockPanel Grid.Row="0" FlowDirection="LeftToRight">
<Button Content="Exit" Command="{Binding ExitApplicationCommand}" Height="60" Width="60" Background="Red"/>
</DockPanel>
</tk:tkWindowControl.TitleBarContent>
我的DependencyProperty 是typeof(FrameWorkElement),因为我喜欢在标题栏中添加几个Buttons。
可以这样使用我的绑定吗?
【问题讨论】:
-
如果您的按钮出现在 UI 中,那么我希望您需要做的就是在窗口的数据上下文中拥有一个公共 iCommand 属性 ExitApplicationCommand。你现在有什么?
-
背景已经完成。我通过将按钮放在普通网格中来尝试绑定。一切正常。但是在
Titlebarcontent中使用的按钮没有IsMouseOverEffect 并且Binding不再起作用。
标签: c# wpf xaml data-binding dependency-properties