我是WPF.I有一个WPF窗口,并在同一个项目中,我有一个WPF PAGE电泳页面包含要加载到window.The窗口中的键盘布局有其源设置为page.Now框架的新手在页面中的所有按钮都WPF定制controls.These控件有像IsCapsOn和IsShiftOn两个依赖属性。 上的按钮改变变化的时候,文本这些依赖特性(“a”变为“A”,表示帽被按下)。 上述的依赖特性绑定到由名称IsCapsPressed和IsShiftPressed主窗口的依赖特性。 当用户按下上主窗口帽键,在后端,结果IsCapsOn也有变动,由于此binding.For我必须设置按钮的数据上下文中页到主窗口因为依赖性能列于它定义IsCapsPressed属性更改。以下是代码snipets:
//page
<Page x:Class="Philips.PmsUS.VirtualKeyboard.Resources.Layouts.USKeyboardPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:kb="clr-namespace:Philips.PmsUS.KeyboardButton;assembly=Philips.PmsUS.KeyboardButton"
mc:Ignorable="d"
x:Name="Layout"
Loaded="Page_Loaded"
Title="USKeyboardPage">
<Grid x:Name="MainGrid"
Width="auto"
Height="auto"
Focusable="True">
<!...Row and column definitions are defined...>
<kb:KeyboardButton Name="Button_Q"
Width="auto"
Height="auto"
Grid.Column="3"
IsCapsOn="{Binding Path=IsCapsPressed}"
IsShiftOn="{Binding Path=IsShiftPressed}"
Focusable="True"
Style="{StaticResource KeyboardButtonStyle}"
Click="NonModifierClick"
DataContext="{Binding ElementName=Keyboardwnd}"></kb:KeyboardButton>
</Grid>
<page>
//window.xaml
<Window x:Class="Philips.PmsUS.VirtualKeyboard.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="KeyboardWindow"
x:Name="Keyboardwnd"
Height="581"
Width="1392"
Topmost="False"
Loaded="Window_Loaded"
FocusManager.IsFocusScope="True"
WindowStartupLocation="Manual"
Background="{DynamicResource KeyboardBackgroundBrush}">
<Grid x:Name="LayoutRoot">
<Frame x:Name="LayoutHolder"
Source="Resources\Layouts\USKeyboardPage.xaml"
></Frame>
</Grid>
</Window>
//mainwindow.xaml.cs
#region dependency properties
//the below dependency properties are used for modifier keys
public static readonly DependencyProperty IsCapsPressedProperty = DependencyProperty.Register("IsCapsPressed", typeof(bool), typeof(MainWindow), new FrameworkPropertyMetadata(new PropertyChangedCallback(SetCapsState)));
public static readonly DependencyProperty IsShiftPressedProperty = DependencyProperty.Register("IsShiftPressed", typeof(bool), typeof(MainWindow), new FrameworkPropertyMetadata(new PropertyChangedCallback(SetShiftState)));
public static readonly DependencyProperty IsGlobePressedProperty = DependencyProperty.Register("IsGlobePressed", typeof(bool), typeof(MainWindow), new FrameworkPropertyMetadata(new PropertyChangedCallback(SetGlobeState)));
#endregion
但上述数据上下文绑定并不是working.Please帮助。