我有两个用户控件:
public partial class MKSelectMonthUC : UserControl
{
public static readonly DependencyProperty CurrentYearProperty = DependencyProperty.Register("CurrentYear", typeof(int), typeof(MKSelectMonthUC), new PropertyMetadata(0));
public int CurrentYear
{
get { return (int)GetValue(CurrentYearProperty); }
set
{
SetValue(CurrentYearProperty, value);
}
}
public static readonly DependencyProperty ChatRoomIdProperty = DependencyProperty.Register("ChatRoomId", typeof(int), typeof(MKSelectMonthUC), new PropertyMetadata(0));
public int ChatRoomId
{
get { return (int)GetValue(ChatRoomIdProperty); }
set
{
SetValue(ChatRoomIdProperty, value);
if(value > 0)
GetChatReport(ChatRoomId);
}
}
}
和
public partial class MKSelectPeriodForChatReportCW : ChildWindow
{
public static readonly DependencyProperty ChatRoomIdProperty = DependencyProperty.Register("ChatRoomId", typeof(int), typeof(MKSelectPeriodForChatReportCW), new PropertyMetadata(0));
public int ChatRoomId
{
get { return (int)GetValue(ChatRoomIdProperty); }
set
{
SetValue(ChatRoomIdProperty, value);
}
}
public static readonly DependencyProperty CurrentYearProperty = DependencyProperty.Register("CurrentYear", typeof(int), typeof(MKSelectPeriodForChatReportCW), new PropertyMetadata(0));
public int CurrentYear
{
get { return (int)GetValue(CurrentYearProperty); }
set
{
SetValue(CurrentYearProperty, value);
}
}
}
在 MKSelectPeriodForChatReportCW 的 XAML 中,我想将它的 DependencyProperties 绑定到 MKSelectMonthUC DependencyProperties,如下所示:
<controls:ChildWindow x:Class="XX.mkControls.MKSelectPeriodForChatReportCW"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:mk="clr-namespace:XX.mkControls.MKSelectPeriodForChatReport"
Name="mainControl"
>
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<mk:MKSelectMonthUC CurrentYear="{Binding CurrentYear, ElementName=mainControl}" ChatRoomId="{Binding ChatRoomId, ElementName=mainControl}" />
</Grid>
MKSelectPeriodForChatReportCW 上的属性确实(从它们的绑定中)获取值,但 MKSelectMonthUC 上的值没有。所以请帮我找到解决方案。谢谢。