2つのUserControlがあります。
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を次のようにMKSelectMonthUCDependencyPropertiesにバインドします。
<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の値は取得しません。だから私が解決策を見つけるのを手伝ってください。ありがとう。