如何在我的主窗口中显示基于窗口1的另一个窗口中的组合框项目选择的图像 为了eaxmple我有这个组合框我的Window1
<ComboBox Height="21" HorizontalAlignment="Left" IsEditable="False" IsReadOnly="False" Margin="297,82,0,0" Name="comboBox13" VerticalAlignment="Top" Width="101" >
<ComboBoxItem Content="ON" />
<ComboBoxItem Content="OFF" />
</ComboBox>
和我的MainWindow
<Image Height="13" HorizontalAlignment="Left" Margin="284,236,0,0" Name="CB2" Source="/WpfApplication3;component/Images/blankSpacer.gif" />
<Image Height="13" HorizontalAlignment="Left" Margin="284,236,0,0" Name="CB3" Source="/WpfApplication3;component/Images/blankSpacer.gif" />
我想要的是当我选择Combobox项目“ON”时应该看到图像CB2,当我选择Combobox项目“OFF”时应该看到图像CB2 我怎么在Wpf
答案 0 :(得分:1)
尝试类似:
CB2.IsVisible = (comboBox12.Text == "ON");
CB3.IsVisible = (comboBox12.Text == "OFF");
在OnChange
ComboBox事件中。
答案 1 :(得分:0)
假设你知道如何正确绑定,我想的是:
<ComboBox Height="21" HorizontalAlignment="Left" IsEditable="False" IsReadOnly="False" Margin="297,82,0,0" Name="comboBox13" VerticalAlignment="Top" Width="101" SelectedIndex={Binding SelectedIndex, Mode=TwoWay"} >
<ComboBoxItem Content="ON" />
<ComboBoxItem Content="OFF" />
</ComboBox>
<Image Height="13" HorizontalAlignment="Left" Margin="284,236,0,0" Name="CB2" Source="/WpfApplication3;component/Images/blankSpacer.gif" Visibility={Binding showcb2, Mode=TwoWay"} />
<Image Height="13" HorizontalAlignment="Left" Margin="284,236,0,0" Name="CB3" Source="/WpfApplication3;component/Images/blankSpacer.gif" Visibility={Binding showcb3, Mode=TwoWay"} />
然后在viewmodel中:
public SelectedIndex{get;set;}
public Visibility showcb2
{
get
{
if (SelectedIndex == 0)
{
return Visibility.Visible;
}
return Visibility.Collapsed;
}
}
public Visibility showcb3
{
get
{
if (SelectedIndex == 0)
{
return Visibility.Visible;
}
return Visibility.Collapsed;
}
}
答案 2 :(得分:0)
你好Jaime Oro我试过你建议但是Ihv Combobox在一个窗口和图像在其他窗口所以它没有采取参考