本文介绍了动态修改列定义宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是wpf初学者...我试图将ColumnDefinition宽度Col0绑定到我的视图模型中的一个属性,以便当ContentControl ContentControl Name="NeedDataEntryControl"
是可见的时,Col0
>width = NeedDataEntryControl.width...
使用MVVM模式时如何实现此目的.
xaml复制到下面..
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..
<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>
推荐答案
For Each c As ColumnDefinition In DisplayGrid.ColumnDefinitions
c.Width = GridLength.Auto
Next
代替< gridlength.auto>您还可以设置column
的值
希望这会有所帮助
Instead of <gridlength.auto> u can also set value of column
Hopefully this will help
这篇关于动态修改列定义宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!