2011-02-16 37 views
0

如何顯示圖像在我的基礎上在另一個窗口的組合框項目選擇的主要窗口,是窗口1 對於eaxmple IHAVE這Comboboxin我的窗口1顯示圖像

<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> 

,並在我的主窗口

<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項「關於」影像CB2應該看到,當我選擇ComboBox項「OFF」圖片CB2應該被看作 如何伊在WPF

回答

1

嘗試類似:

CB2.IsVisible = (comboBox12.Text == "ON"); 
CB3.IsVisible = (comboBox12.Text == "OFF"); 

OnChange組合框的事件。

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"} /> 

然後在視圖模型:

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; 
    }   
} 
0

嗨海梅奧羅我嘗試了你的建議,但IHV在組合框一個窗口和其他窗口中的圖像所以它不是參考文獻

+0

這屬於一個評論... –

+0

@ HB有1個聲望的人無法評論。 –