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
将combobox选定值作为另一个控件wpf的dataTemplate的键_Wpf_Templates_Binding_Controls - Fatal编程技术网

将combobox选定值作为另一个控件wpf的dataTemplate的键

将combobox选定值作为另一个控件wpf的dataTemplate的键,wpf,templates,binding,controls,Wpf,Templates,Binding,Controls,我有一个组合框: <Grid> <ComboBox Height="52" HorizontalAlignment="Left" ItemsSource="{Binding templatesNames}" SelectedValuePath="Type.FullName" Margin="169,43,0,0" Name="comboBox1"

我有一个组合框:

   <Grid>

    <ComboBox Height="52" HorizontalAlignment="Left"
              ItemsSource="{Binding templatesNames}"
              SelectedValuePath="Type.FullName"         
              Margin="169,43,0,0" Name="comboBox1" 
              VerticalAlignment="Top" Width="148" />

    <Button Content="Button"
   ***Template="{Binding key = Converter={Binding SelectedItem.Value,ElementName=comboBox1}}"
            Height="56" HorizontalAlignment="Left" 
            Margin="191,204,0,0" Name="button1" 
            VerticalAlignment="Top" Width="80" />
</Grid>

问题已与签名* 我有templatesNames如何保存模板的名称 我想将这些名称转换为按钮将要绑定到的密钥(模板密钥)

我该怎么做?。。。 转换器应该做什么?需要吗?我可以不用它吗

编辑: 这就是我现在所做的:

    <ComboBox x:Name="ComboBox1"
                              ItemsSource="{Binding collection}" 
                               Margin="553,0,0,13" 
                              SelectedValuePath="Type.FullName" SelectedIndex="1"
                              FontFamily="Buxton Sketch"
                              FontSize="20" HorizontalAlignment="Left" Width="231" Height="46"     VerticalAlignment="Bottom" />

其中集合是公共可观察集合集合{get;set;}

该按钮与@Meleak按钮类似,项目名称空间为clr名称空间:dinamicGridLayout
我是否应该在转换器Uri resourceLocater=新Uri(@“clr命名空间:dinamicGridLayout;ResourceDictionary1.xaml”,System.UriKind.Relative)

如果将所有ControlTemplates放在一个资源字典中,则可以对模板使用如下转换器

<ComboBox Height="52" HorizontalAlignment="Left" 
          ItemsSource="{Binding templatesNames}" 
          SelectedValuePath="Type.FullName"          
          Margin="169,43,0,0" Name="comboBox1"  
          VerticalAlignment="Top" Width="148" /> 

<Button Content="Button" 
        Template="{Binding SelectedItem.Value,
                           ElementName=comboBox1,
                           Converter={StaticResource TemplateConverter}}"
        Height="56" HorizontalAlignment="Left"  
        Margin="191,204,0,0" Name="button1"  
        VerticalAlignment="Top" Width="80" />
Uri resourceLocater = new Uri("/dinamicGridLayout;component/Dictionary1.xaml", System.UriKind.Relative);
更新

如果名称空间是dinamicGridLayout,那么转换器应该如下所示

<ComboBox Height="52" HorizontalAlignment="Left" 
          ItemsSource="{Binding templatesNames}" 
          SelectedValuePath="Type.FullName"          
          Margin="169,43,0,0" Name="comboBox1"  
          VerticalAlignment="Top" Width="148" /> 

<Button Content="Button" 
        Template="{Binding SelectedItem.Value,
                           ElementName=comboBox1,
                           Converter={StaticResource TemplateConverter}}"
        Height="56" HorizontalAlignment="Left"  
        Margin="191,204,0,0" Name="button1"  
        VerticalAlignment="Top" Width="80" />
Uri resourceLocater = new Uri("/dinamicGridLayout;component/Dictionary1.xaml", System.UriKind.Relative);

上传了小样本项目。

看起来不错,但有两个问题:1.StaticResource??你对这件事傻乎乎的吗?2./名称空间;component/Dictionary1.xaml“假设我的名字空间是xxxx,应该是”clr名称空间:xxx;字典1.xaml“?