Note that there are some explanatory texts on larger screens.

plurals
  1. POShow/Hide items in itemscontrol on condition
    primarykey
    data
    text
    <p>I have an Itemscontrol that I am using to display a list of start information sent from a timing system.</p> <p>I need to be able to "switch off"/stop displaying a set of lane info if the lane number isn't showing (if it's null or a blank) and then if the timer sends info to switch the lane back on then show the data again.</p> <p>I can't set it to just delete everything because the timer sends its information constantly and everything except the lane number would reappear again.</p> <p>Is it possible to show/hide items on condition?</p> <p>What is currently happening</p> <pre><code>Lanes 1 ------ 2 ------ ------ &lt;- other info remains 4 ------ </code></pre> <p>What I want to happen</p> <pre><code>Lanes 1 ------ 2 ------ 4 ------ </code></pre> <p>Here is a sample of my itemscontrol code</p> <pre><code>&lt;ItemsControl ItemsSource="{Binding CHeat.SwimList}" Margin="10,0" HorizontalAlignment="Left" VerticalAlignment="Top"&gt; &lt;ItemsControl.Template&gt; &lt;ControlTemplate TargetType="ItemsControl"&gt; &lt;StackPanel&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Label Content="Lane" /&gt; &lt;Label Content="Pos" /&gt; &lt;Label Content="Swimmer" /&gt; &lt;Label Content="Club" /&gt; &lt;Label Content="Time" /&gt; &lt;/StackPanel&gt; &lt;ItemsPresenter/&gt; &lt;/StackPanel&gt; &lt;/ControlTemplate&gt; &lt;/ItemsControl.Template&gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;StackPanel/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="35" /&gt; &lt;ColumnDefinition Width="30" /&gt; &lt;ColumnDefinition Width="150" /&gt; &lt;ColumnDefinition Width="50" /&gt; &lt;ColumnDefinition Width="80" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Label Grid.Column="0" Content="{Binding LaneNumber}" /&gt; &lt;Label Grid.Column="1" Content="{Binding Position}" /&gt; &lt;Label Grid.Column="2" Content="{Binding Swimmer}" /&gt; &lt;Label Grid.Column="3" Content="{Binding Club}" /&gt; &lt;Label Grid.Column="4" Content="{Binding Time}" /&gt; &lt;/Grid&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; </code></pre> <p>If there was a way I could set <code>Content = ""</code> for the other data based off the LaneNumber then I believe it could work, because then I can just bring back the bindings.</p> <p>I'm fairly new to WPF so extra detail would be helpful many thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. CO`Is it possible to show/hide items on condition?` -> Yes it's called `Triggers` has multiple types. For your case, you could be using a `DataTrigger` to check if the Lane number is null/empty and if so set the `Visibility` of that item to `Hidden`. just google to see examples for `DataTrigger`. Also if your new to WPF, `Label` has a specific purpose in WPF. It does a whole load more than just display "text", if you're just after showing text, use a `TextBlock`. Also check some example's for WPF Layout's. What you're doing isn't "wrong" but could be done better.
      singulars
    2. CO@Viv Thanks I'll see what I can come up with that should work. In what way do you think I could improve the layout? It is a WIP so it looks a bit all over the place at the moment but I was more concerned about it being functional.
      singulars
    3. COYou're welcome. As for the layout, say things like in the `DataTemplate` why nest a `Grid` inside a `StackPanel` when it's the only child. Also Fixed Width's in WPF is frowned upon **unless** essential. In your case you got the column size's fixed and thus it ain't scalable. You could use "*" based multipliers to allocate space for Grid control's based on a percentage of what's available. If you just need fixed dimension, you might as well specify the Width on the item's and get rid of the `Grid`. You ain't going to get it all in a day, If you're tryin that's good enough. Just keep refining.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload