У меня есть окно, которое выглядит как этотWPF связать кнопку из шаблона окна для команды ViewModel в
Как Вы можете видеть, что есть кнопки на «панели окна» сама, и Я хочу, чтобы связать команду кнопки повелению ViewModel в
Вот как визуальное дерево выглядит
Я пробовал различные combinatios с помощью RelativeSource, но не может найти способ, чтобы это работало ..
Любой вид помощи или идеи будут оценены
Код для самого окна ..
<dx:DXWindow x:Class="Chronos.WindowsApp.Windows.TimersCollectionWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:themes="http://schemas.devexpress.com/winfx/2008/xaml/core/themekeys"
mc:Ignorable="d"
Title="Timers"
ShowInTaskbar = "False"
ShowIcon="True" Icon="/Chronos.UserControls;component/Images/TimersWindowIconW.png"
d:DesignHeight="80" d:DesignWidth="80"
>
<dx:DXWindow.Resources>
<ControlTemplate x:Key="{themes:FloatingContainerThemeKey ThemeName=Mishcon, ResourceKey=FloatingContainerDragWidgetTemplate, IsThemeIndependent=True}" TargetType="{x:Type Thumb}">
<Border Height="40" Background="Transparent" DockPanel.Dock="Left">
<DockPanel HorizontalAlignment="Left">
<Button DockPanel.Dock="Left" Background="Transparent"
Width="70"
Height="35"
Command="{Binding RelativeSource={RelativeSource AncestorType=dx:DXWindow}, Path=RootControl.DataContext.NewTimmerCommand}"
>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Image Source="{dx:DXImage Image=Add_32x32.png}" Width="24" VerticalAlignment="Center"/>
<TextBlock Text="Add" FontWeight="Bold" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</DockPanel>
</Border>
</ControlTemplate>
</dx:DXWindow.Resources>
</dx:DXWindow>
ошибка я получаю:
System.Windows.Data Error: 40 : BindingExpression path error: 'RootControl' property not found on 'object' ''TimersCollectionWindow' (Name='')'. BindingExpression:Path=RootControl.DataContext.NewTimmerCommand; DataItem='TimersCollectionWindow' (Name=''); target element is 'Button' (Name=''); target property is 'Command' (type 'ICommand')
Вы пробовали '{Binding RelativeSource = {RelativeSource AncestorType = дх: DXWindow}, Path = DataContext.NewTimmerCommand}" ' – StepUp
Не могли бы вы показать XAML окна (упрощенный) –
@Michal - как бы я сделать это? ? – Marty