English 中文(简体)
翻新项目的项目
原标题:Stretching the items of an ItemsControl

我在此推敲了一个小型的WPF。 它完全是用微型和小型设备建造的,只使用与观察模型类型有关的数据模板。

我看到了关于如何扩展和删除<代码>ListBox内容以便这些物品能够填满母子的问题。 经过一段试验之后,我得以接手,但现在我发现自己处于与<代码>ItemsControl

此处为<代码>DataTemplates in use(一个简单的TextBox)。 说明我是如何尝试制定<代码>HorizontalAlignment的。

<DataTemplate DataType="{x:Type vm:OneOfMyViewModelTypes}">
    <TextBox 
        Text="{Binding Path=Value}"
        HorizontalAlignment="Stretch"
        />
</DataTemplate>

参看<代码>ItemsControl载于/code>。 ......

<Grid Background="Gray">
            <Grid.Margin>
                <Thickness 
                    Left="{StaticResource ConfigurationDefaultMargin}" 
                    Right="{StaticResource ConfigurationDefaultMargin}" 
                    Bottom="{StaticResource ConfigurationDefaultMargin}" 
                    Top="{StaticResource ConfigurationDefaultMargin}" 
                    />
            </Grid.Margin>
            <Grid.ColumnDefinitions>
                <ColumnDefinition SharedSizeGroup="_key" Width="Auto"/>
                <ColumnDefinition SharedSizeGroup="_value" Width="*"/>
            </Grid.ColumnDefinitions>

            <ItemsControl 
                Background="DimGray" 
                Grid.IsSharedSizeScope="True"
                ItemsSource="{Binding Path=Configuration, Mode=OneWay}" 
                HorizontalAlignment="Stretch" 
                HorizontalContentAlignment="Stretch"
                >
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition SharedSizeGroup="_key"/>
                                <ColumnDefinition SharedSizeGroup="_value"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock
                                Style="{StaticResource ExtensionConfigurationLabel}"
                                Grid.Column="0"
                                Margin="5,5,5,0"
                                Text="{Binding Path=Caption}" 
                                />
                            <ContentPresenter 
                                Grid.Column="1"
                                HorizontalAlignment="Stretch"
                                Margin="5,5,5,0"
                                Content="{Binding}" 
                                />
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>

我用颜色来看待控制的规模。

结果是......

“这一结果”</p

如您从颜色中可以看到,其中包含<代码>Grid/code>。 <代码>ItemsControl不适用。 我的确将其<代码>HorizontalAlignment property to Stretch,但似乎没有任何效果。 我是否需要做什么?

成就

最佳回答

You have two columns in your main (outer) grid, yet you use only the first column. The second column uses all the remaining space.

问题回答

暂无回答




相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签