views:

28

answers:

0

I was wondering how to increase the span of a listbox control for a certain criteria in WPF Grid. I have a textbox wherein the user enters a string and based on the presence of the string in a collection, the listbox should become visible and show the results in it by spanning across the columns of the grid. This listbox is actually a part of a user control called LoadControl which has a separate template defined to load the listbox only when items are there in it. This LoadControl is added in another user control along with Advanced button. The same row in the Grid also has two other controls which are visible only when the load is in progress. If I add the LoadControl to the first column then on load results the listbox appears only in the first column as a drop down to the textbox which is undesirable. Else if I a say Grid.Span=4 for the LoadControl, when the user control is loaded since the other two controls in the third and fourth columns are visible based on a condition, the LoadControl spans across and UI looks cluttered.

xaml for this like below :

            <Grid  >
                  <Grid.RowDefinitions>
                   <RowDefinition Height="Auto"/>
                   </Grid.RowDefinitions>
                   <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="*"/>
                      <ColumnDefinition Width="*"></ColumnDefinition>
                      <ColumnDefinition Width="*"/>
                       <ColumnDefinition Width="Auto"/>
                      </Grid.ColumnDefinitions>
                       <ctrl:LoadControl   HorizontalAlignment="Stretch" VerticalAlignment="Top"        Grid.Column="0" Items ="{Binding LoadResults}" Command="{Binding LoadCommand}"    CommandParameter="{Binding Text, RelativeSource={RelativeSource Self}}" >
</ctrl:LoadControl   >
                   <Border Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" >
                         <Button  Content="Advanced" Command="{Binding AdornerCommand}" CommandParameter="ShowFilter" />
                    </Border>
                  <Border Grid.Column="2" BorderThickness="1" Grid.ColumnSpan="2" Margin="4,0,25,0">
                   <TextBlock 
                       Visibility="{Binding Path=IsLoadInProgress, Converter={StaticResource  MyBooleanToVisibilityConverter}, Mode=TwoWay}">
                 <Hyperlink  Command="{Binding StopCommand}">
                      <TextBlock Text="Stop" ></TextBlock>
                 </Hyperlink>
               </TextBlock>
                </Border>
                 <Border Grid.Row="0" Grid.Column="3" BorderThickness="1"  Visibility="{Binding Path=IsLoadInProgress, Converter={StaticResource MyBooleanToVisibilityConverter}, Mode=TwoWay}">
               <ctrl:LoadProgress  Height="23" Width="23" VerticalAlignment="Top"></ctrl:LoadProgress>
                      </Border>                                
                    </Grid>

Could anyone please suggest how do I achieve this?