开发者

Display image Based on Combobox Item Selection

开发者 https://www.devze.com 2023-02-10 15:22 出处:网络
How Do i Display Image in my main Window based on combobox Item Selection in another Window that is Window 1

How Do i Display Image in my main Window based on combobox Item Selection in another Window that is Window 1 For eaxmple Ihave This Comboboxin my Window1

<ComboBox Height="2开发者_如何学Go1" HorizontalAlignment="Left" IsEditable="False" IsReadOnly="False" Margin="297,82,0,0" Name="comboBox13" VerticalAlignment="Top" Width="101" >
    <ComboBoxItem Content="ON" />
    <ComboBoxItem Content="OFF" />
</ComboBox>

and in my 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" />

what I want is When I select Combobox item "ON" Image CB2 should be seen and when I select Combobox item "OFF" Image CB2 should be seen How do Ido that in Wpf


Try something like:

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

In the OnChange ComboBox event.


Assuming you know how to properly bind, i'm thinking something like:

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

Then in the 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;
    }           
}


Hi Jaime Oro I Tried A you Suggested but Ihv Combobox in one Window and Image in Other Window So it is not Taking the Refrence

0

精彩评论

暂无评论...
验证码 换一张
取 消