Wpf wp8通过DataTemplate将复选框绑定到CustomMessageBox
我自己控制。 在里面,我想定义数据模板,以便在自定义消息框中使用它。 在代码中,我打开了这个对话框,但无法在其中设置“开始值”复选框 请帮助我-如何通过名为VoiceTemplate的数据模板将cbVoiceAttChecked变量正确绑定到CustomMessageBox XAML:Wpf wp8通过DataTemplate将复选框绑定到CustomMessageBox,wpf,xaml,windows-phone-8,datatemplate,Wpf,Xaml,Windows Phone 8,Datatemplate,我自己控制。 在里面,我想定义数据模板,以便在自定义消息框中使用它。 在代码中,我打开了这个对话框,但无法在其中设置“开始值”复选框 请帮助我-如何通过名为VoiceTemplate的数据模板将cbVoiceAttChecked变量正确绑定到CustomMessageBox XAML: 您需要将cbVoiceAttChecked属性更改为DependencyProperty,或者在RDPControl类中实现INotifyPropertyChanged接口 您可以在MSDN上的和页面中找到有关I
您需要将
cbVoiceAttChecked
属性更改为DependencyProperty
,或者在RDPControl
类中实现INotifyPropertyChanged
接口
您可以在MSDN上的和页面中找到有关INotifyPropertyChanged
接口的更多信息,以及关于dependencProperty
s的更多信息
当然,这完全取决于您在
RDPControl
类中对ContentTemplate
对象所做的操作。由于您没有显示这一点,我无法确认进行上述更改是否会解决您的问题。我尝试使用INotifyPropertyChanged-问题相同!
<UserControl x:Class="myProj.RDPControl"
...
>
<UserControl.Resources>
<DataTemplate x:Key="VoiceTemplate" >
<StackPanel Margin="32,0,0,0">
<CheckBox x:Name="cbVoiceAtt" Content="..." IsChecked="{Binding cbVoiceAttChecked}"/>
... /*Other checkboxes*/
</StackPanel>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
... Here is main control - works perfectly
</Grid>
public partial class RDPControl : UserControl
{
public RDPControl()
{
InitializeComponent();
//this.DataContext = this;
}
public bool cbVoiceAttChecked { get; set; }
....
private void VoiceButton_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
cbVoiceAttChecked = true; // This value binding to temlate!!!
CustomMessageBox messageBox = new CustomMessageBox()
{
Caption = "...",
Message = "...",
ContentTemplate = (DataTemplate)(this.Resources["VoiceTemplate"]), // Use template from xaml
DataContext = this, // I want to use cbVoiceAttChecked variable to bind to dialog
LeftButtonContent = "yes",
RightButtonContent = "no"
};
...
messageBox.Show();
}