Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm a wpf beginner... i'm trying to bind the ColumnDefinition width, Col0 to a property in my viewmodel so that when the ContentControl ContentControl Name="NeedDataEntryControl" is visible ,the Col0 >width = NeedDataEntryControl.width... how do i achieve this when using MVVM pattern..
The xaml is copied below..

HTML
<grid scrollviewer.verticalscrollbarvisibility="Disabled" name="allEntityGrid" scrollviewer.previewmousewheel="allEntity_PreviewMouseWheel">
        
        <grid.rowdefinitions>
            <rowdefinition height="*"></rowdefinition>
        </grid.rowdefinitions>
        <grid.columndefinitions>
            <columndefinition name="Col0" sharedsizegroup="shareThis" />
            <columndefinition name="ColSplitter" width="5"></columndefinition>
            <columndefinition name="Col2" width="*"></columndefinition>
        </grid.columndefinitions>
        <border borderthickness="1" borderbrush="#ACACAC">
        <scrollviewer name="NeedScrollViewer" verticalscrollbarvisibility="Auto" previewmousewheel="allEntity_PreviewMouseWheel">
            <grid name="needGrid" visibility="{Binding Path=HighLevelFilterMask, Converter={StaticResource HighLevelFilterMaskToVisibilityForNeed}}">

                <grid.rowdefinitions>
                    <rowdefinition height="Auto"></rowdefinition>
                    <rowdefinition height="*"></rowdefinition>

                </grid.rowdefinitions>
                    <contentcontrol name="NeedDataEntryControl" content="{Binding Path=NewNeedViewModel}" contenttemplate="{DynamicResource NeedDataEntryDataTemplate}">
                    <contentcontrol.style>
                        <Style TargetType="{x:Type ContentControl}">
                            <Style.Triggers>
                                    <datatrigger binding="{Binding Path=NewNeedViewModel.NeedDataEntryControlVisibility}" value="Collapsed">
                                    <setter property="Visibility" value="Collapsed" />
                                </datatrigger>
                                    <datatrigger binding="{Binding Path=NewNeedViewModel.NeedDataEntryControlVisibility}" value="Visible">
                                    <setter property="Visibility" value="Visible" />
                                </datatrigger>
                            </Style.Triggers>
                        </Style>
                    </contentcontrol.style>
                </contentcontrol>

                <local:careplanlistbox isincludedinglobalunselection="True" scrollviewer.horizontalscrollbarvisibility="Disabled" x:name="lstBoxAllNeeds" selectionmode="Single" xmlns:x="#unknown" xmlns:local="#unknown">
                  Grid.Row="1" Grid.Column="0"  HorizontalContentAlignment="Stretch"
                   ItemsSource="{Binding NeedsCollectionView}" ItemContainerStyle="{DynamicResource NeedCarePlanListBoxItem}"
                                        ItemTemplate="{DynamicResource NeedDataTemplateCompact}" AlternationCount="2" BorderThickness="0"></local:careplanlistbox>

            </grid>
        </scrollviewer>
        </border>
        <gridsplitter name="GridSplitter" dragincrement="{Binding }" resizebehavior="PreviousAndNext" removed="#FFFFFF" grid.row="0" grid.column="1" width="Auto" horizontalalignment="Stretch" verticalalignment="Stretch" resizedirection="Columns">
         
        </gridsplitter>


        <listbox isincludedinglobalunselection="True" scrollviewer.horizontalscrollbarvisibility="Disabled" x:name="lstBoxAllExecutions" selectionmode="Single" xmlns:x="#unknown">
               Grid.Row="0" Grid.Column="2"  HorizontalContentAlignment="Stretch"  ItemContainerStyle="{DynamicResource ExecutionCarePlanListBoxItem}"
               ItemTemplate="{DynamicResource ExecutionTemplate}"   ItemsSource="{Binding ExecutionsCollectionView}"
               AlternationCount="2" PreviewMouseWheel="lstAllExecutions_PreviewMouseWheel"
               Visibility="{Binding Path=HighLevelFilterMask, Converter={StaticResource HighLevelFilterMaskToVisibilityForExecution}}"  BorderBrush="#ACACAC" BorderThickness="1">
           
        </listbox>

        

    </grid>
Posted
Updated 7-Dec-11 15:54pm
v4
Comments
[no name] 7-Dec-11 21:55pm    
EDIT: added code blocks

1 solution

Here is some code

VB
For Each c As ColumnDefinition In DisplayGrid.ColumnDefinitions
          c.Width = GridLength.Auto
      Next


Instead of <gridlength.auto> u can also set value of column

Hopefully this will help
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900