locked
Hide/Show Controls on combobox selection RRS feed

  • Question

  • Hi

    I am a BA working with Blends 4. I am having trouble working with combobox selection. I have 4 states that I want to connect to the four values in the combobox, though I am able to assign repective states to the values of the combobox from the OBJECTS and TIMELINES view, but when I run it; it only changes state to the default state and when select any other value it remains the same....

    Please I need help with this and I am raising this thread again because I cant work with code to solve this, I need help to configure this from the UI, if possible..

     

    Thanks in advance...

    Regards

    SA

     

    Monday, October 31, 2011 9:55 PM

Answers

  • One way to do it is to put the behaviors on the combobox and use the selectedindex to match which state to invoke. You could also use SelectedValue in a similar way.

    Here is xaml that I believe does what you want.

    <ComboBox x:Name="comboBox1" Height="14" Margin="280,127,248,0" Style="{StaticResource ComboBox-Sketch}" VerticalAlignment="Top">
       <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
        	<i:Interaction.Behaviors>
        		<ei:ConditionBehavior>
        			<ei:ConditionalExpression>
        				<ei:ComparisonCondition RightOperand="0" LeftOperand="{Binding SelectedIndex, ElementName=comboBox1}"/>
        			</ei:ConditionalExpression>
        		</ei:ConditionBehavior>
        	</i:Interaction.Behaviors>
         <pi:ActivateStateAction TargetState="File"/>
        </i:EventTrigger>
        <i:EventTrigger EventName="SelectionChanged">
        	<i:Interaction.Behaviors>
        		<ei:ConditionBehavior>
        			<ei:ConditionalExpression>
        				<ei:ComparisonCondition RightOperand="2" LeftOperand="{Binding SelectedIndex, ElementName=comboBox1}"/>
        			</ei:ConditionalExpression>
        		</ei:ConditionBehavior>
        	</i:Interaction.Behaviors>
        	<pi:ActivateStateAction TargetState="ECR"/>
        </i:EventTrigger>
        <i:EventTrigger EventName="SelectionChanged">
        	<i:Interaction.Behaviors>
        		<ei:ConditionBehavior>
        			<ei:ConditionalExpression>
        				<ei:ComparisonCondition RightOperand="1" LeftOperand="{Binding SelectedIndex, ElementName=comboBox1}"/>
        			</ei:ConditionalExpression>
        		</ei:ConditionBehavior>
        	</i:Interaction.Behaviors>
        	<pi:ActivateStateAction TargetState="RAC"/>
        </i:EventTrigger>
       </i:Interaction.Triggers>
       <ComboBoxItem Content="File Note" IsSelected="True">
        <ComboBoxItem.DataContext>
         <i:EventTrigger EventName="CollectionChanged" SourceName="comboBoxItem" SourceObject="{Binding Actions}"/>
        </ComboBoxItem.DataContext>
       </ComboBoxItem>
       <ComboBoxItem Content="RAC Note"/>
       <ComboBoxItem Content="ECR Note"/>
      </ComboBox>
    


    Wednesday, November 2, 2011 4:19 PM
    Moderator

All replies

  • FYI

    And I am working with a Silverlight Mockup.

    Monday, October 31, 2011 9:57 PM
  • Could you please post the xaml you are using?
    Tuesday, November 1, 2011 1:50 PM
    Moderator
  • Please find below

     

    <UserControl
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:pi="http://schemas.microsoft.com/prototyping/2010/interactivity"
     xmlns:System="clr-namespace:System;assembly=mscorlib"
     xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
     mc:Ignorable="d"
     x:Class="Admin_PageScreens.Add_Notes"
     Width="640" Height="480">

     <Grid x:Name="LayoutRoot" Background="White">
      <VisualStateManager.VisualStateGroups>
       <VisualStateGroup x:Name="ShowHide">
        <VisualState x:Name="File">
         <Storyboard>
          <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock" d:IsOptimized="True"/>
          <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock1" d:IsOptimized="True"/>
          <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBox" d:IsOptimized="True"/>
          <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="comboBox" d:IsOptimized="True"/>
          <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="checkBox" d:IsOptimized="True"/>
         </Storyboard>
        </VisualState>
        <VisualState x:Name="RAC">
         <Storyboard>
          <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock1" d:IsOptimized="True"/>
          <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="comboBox" d:IsOptimized="True"/>
         </Storyboard>
        </VisualState>
        <VisualState x:Name="ECR">
         <Storyboard>
          <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock" d:IsOptimized="True"/>
          <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBox" d:IsOptimized="True"/>
          <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="checkBox" d:IsOptimized="True"/>
         </Storyboard>
        </VisualState>
       </VisualStateGroup>
      </VisualStateManager.VisualStateGroups>
      <TextBlock HorizontalAlignment="Left" Height="24" Margin="6,10,0,0" Style="{StaticResource TextBlock-Sketch}" TextWrapping="Wrap" Text="Add Notes:" VerticalAlignment="Top" Width="98" FontSize="18.667"/>
      <TextBox Margin="32,59,32,16" Style="{StaticResource TextBox-Sketch}" TextWrapping="Wrap" Text="113300031P1 - Parker, Rob +" FontSize="16"/>
      <ListBox Margin="93,109,88,48" Style="{StaticResource ListBox-Sketch}"/>
      <TextBox Height="64" Margin="280,0,112,136" Style="{StaticResource TextBox-Sketch}" TextWrapping="Wrap" VerticalAlignment="Bottom"/>
      <TextBlock Height="24" Margin="119,0,0,176" Style="{StaticResource TextBlock-Sketch}" TextWrapping="Wrap" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="88" Text="Note Text"/>
      <TextBlock x:Name="textBlock" Height="24" Margin="119,178,0,0" Style="{StaticResource TextBlock-Sketch}" TextWrapping="Wrap" Text="Next Court Appearance" VerticalAlignment="Top" HorizontalAlignment="Left" Width="136"/>
      <TextBlock x:Name="textBlock1" Margin="119,227,0,233" Style="{StaticResource TextBlock-Sketch}" TextWrapping="Wrap" Text="Accused" HorizontalAlignment="Left" Width="56"/>
      <TextBox x:Name="textBox" Margin="280,173,248,0" Style="{StaticResource TextBox-Sketch}" TextWrapping="Wrap" Text="read only" FontSize="16" Height="32" VerticalAlignment="Top" IsReadOnly="True"/>
      <ComboBox x:Name="comboBox" Height="8" Margin="280,223,248,228" Style="{StaticResource ComboBox-Sketch}">
       <ComboBoxItem x:Name="comboBoxItem" Content="Accused 1"/>
       <ComboBoxItem x:Name="comboBoxItem1" Content="Accused 2"/>
       <ComboBoxItem x:Name="comboBoxItem2" Content="Accused 3"/>
      </ComboBox>
      <TextBlock Margin="120,130,0,0" Style="{StaticResource TextBlock-Sketch}" TextWrapping="Wrap" Text="Note Type" Height="23" VerticalAlignment="Top" HorizontalAlignment="Left" Width="72"/>
      <CheckBox x:Name="checkBox" Content="Carry Forward" HorizontalAlignment="Right" Height="24" Margin="0,181,115,0" Style="{StaticResource CheckBox-Sketch}" VerticalAlignment="Top" Width="120" IsChecked="True"/>
      <Button Content="OK" HorizontalAlignment="Right" Height="24" Margin="0,0,187,72" Style="{StaticResource Button-Sketch}" VerticalAlignment="Bottom" Width="56">
       <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
         <pi:NavigateToScreenAction TargetScreen="Admin_PageScreens.Screen_1"/>
        </i:EventTrigger>
       </i:Interaction.Triggers>
      </Button>
      <Button x:Name="button" Content="CANCEL" HorizontalAlignment="Right" Height="24" Margin="0,0,115,72" Style="{StaticResource Button-Sketch}" VerticalAlignment="Bottom" Width="56">
       <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
         <pi:NavigateToScreenAction TargetScreen="Admin_PageScreens.Screen_1"/>
        </i:EventTrigger>
       </i:Interaction.Triggers>
      </Button>
      <ComboBox Height="14" Margin="280,127,248,0" Style="{StaticResource ComboBox-Sketch}" VerticalAlignment="Top">
       <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
         <pi:ActivateStateAction TargetState="File"/>
        </i:EventTrigger>
       </i:Interaction.Triggers>
       <ComboBoxItem Content="File Note" IsSelected="True">
        <i:Interaction.Triggers>
         <i:EventTrigger EventName="GotFocus">
          <pi:ActivateStateAction TargetState="File"/>
         </i:EventTrigger>
        </i:Interaction.Triggers>
        <ComboBoxItem.DataContext>
         <i:EventTrigger EventName="CollectionChanged" SourceName="comboBoxItem" SourceObject="{Binding Actions}"/>
        </ComboBoxItem.DataContext>
       </ComboBoxItem>
       <ComboBoxItem Content="RAC Note">
        <i:Interaction.Triggers>
         <i:EventTrigger EventName="GotFocus">
          <pi:ActivateStateAction TargetState="RAC"/>
         </i:EventTrigger>
        </i:Interaction.Triggers>
       </ComboBoxItem>
       <ComboBoxItem Content="ECR Note">
        <i:Interaction.Triggers>
         <i:EventTrigger EventName="GotFocus">
          <pi:ActivateStateAction TargetState="ECR"/>
         </i:EventTrigger>
        </i:Interaction.Triggers>
       </ComboBoxItem>
      </ComboBox>
     </Grid>
    </UserControl>

     

    Thanks in Anticipation

    SA

    Tuesday, November 1, 2011 4:52 PM
  • PLease advise soon, if possible.
    Wednesday, November 2, 2011 3:01 PM
  • One way to do it is to put the behaviors on the combobox and use the selectedindex to match which state to invoke. You could also use SelectedValue in a similar way.

    Here is xaml that I believe does what you want.

    <ComboBox x:Name="comboBox1" Height="14" Margin="280,127,248,0" Style="{StaticResource ComboBox-Sketch}" VerticalAlignment="Top">
       <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
        	<i:Interaction.Behaviors>
        		<ei:ConditionBehavior>
        			<ei:ConditionalExpression>
        				<ei:ComparisonCondition RightOperand="0" LeftOperand="{Binding SelectedIndex, ElementName=comboBox1}"/>
        			</ei:ConditionalExpression>
        		</ei:ConditionBehavior>
        	</i:Interaction.Behaviors>
         <pi:ActivateStateAction TargetState="File"/>
        </i:EventTrigger>
        <i:EventTrigger EventName="SelectionChanged">
        	<i:Interaction.Behaviors>
        		<ei:ConditionBehavior>
        			<ei:ConditionalExpression>
        				<ei:ComparisonCondition RightOperand="2" LeftOperand="{Binding SelectedIndex, ElementName=comboBox1}"/>
        			</ei:ConditionalExpression>
        		</ei:ConditionBehavior>
        	</i:Interaction.Behaviors>
        	<pi:ActivateStateAction TargetState="ECR"/>
        </i:EventTrigger>
        <i:EventTrigger EventName="SelectionChanged">
        	<i:Interaction.Behaviors>
        		<ei:ConditionBehavior>
        			<ei:ConditionalExpression>
        				<ei:ComparisonCondition RightOperand="1" LeftOperand="{Binding SelectedIndex, ElementName=comboBox1}"/>
        			</ei:ConditionalExpression>
        		</ei:ConditionBehavior>
        	</i:Interaction.Behaviors>
        	<pi:ActivateStateAction TargetState="RAC"/>
        </i:EventTrigger>
       </i:Interaction.Triggers>
       <ComboBoxItem Content="File Note" IsSelected="True">
        <ComboBoxItem.DataContext>
         <i:EventTrigger EventName="CollectionChanged" SourceName="comboBoxItem" SourceObject="{Binding Actions}"/>
        </ComboBoxItem.DataContext>
       </ComboBoxItem>
       <ComboBoxItem Content="RAC Note"/>
       <ComboBoxItem Content="ECR Note"/>
      </ComboBox>
    


    Wednesday, November 2, 2011 4:19 PM
    Moderator
  • THANKS i'' TRY..Hopefully it works..:)
    Wednesday, November 2, 2011 6:55 PM
  • It worked...thnx a lot..

    Regards

    Saurabh

    Wednesday, November 2, 2011 7:02 PM