Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf wp8通过DataTemplate将复选框绑定到CustomMessageBox_Wpf_Xaml_Windows Phone 8_Datatemplate - Fatal编程技术网

Wpf wp8通过DataTemplate将复选框绑定到CustomMessageBox

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

我自己控制。 在里面,我想定义数据模板,以便在自定义消息框中使用它。 在代码中,我打开了这个对话框,但无法在其中设置“开始值”复选框

请帮助我-如何通过名为VoiceTemplate的数据模板将cbVoiceAttChecked变量正确绑定到CustomMessageBox

XAML:


您需要将
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(); 
    }