在DependencyProperty中使用数据绑定

问题描述 投票:1回答:1

我创建了一个继承自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里面,我添加了一个ContentControlfor这个属性。现在我想在另一个应用程序中使用新的'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),因为我想在Titlebar添加几个Buttons

是否可以这种方式使用我的Bindings?

c# wpf xaml data-binding dependency-properties
1个回答
1
投票

WindowChrome.IsHitTestVisibleInChrome附加属性Button或父元素设置为true

<Button Content="Exit" WindowChrome.IsHitTestVisibleInChrome="True" ... />

或者,您应该减小CaptionHeightWindowChrome属性的值。

© www.soinside.com 2019 - 2024. All rights reserved.