することは可能ですかListBox ItemTemplateを伸ばして水平に全幅のListBox?

StackOverflow https://stackoverflow.com/questions/838828

  •  22-07-2019
  •  | 
  •  

質問

たいていのListItems延長するとオレンジの背景に全幅のListbox.

現在おこなっているだけ多くの名+LastName.

私の設定の全ての要素ができます:HorizontalAlignment="Stretch".

たいの背景ListboxItemsの拡大として、ユーザの手のListboxいて絶対値です。

何かいいことの背景色のListBoxItems記入の幅ListBox?

<Window x:Class="TestListBoxSelectedItemStyle.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TestListBoxSelectedItemStyle"
    Title="Window1" Height="300" Width="300">

    <Window.Resources>
        <local:CustomerViewModel x:Key="TheDataProvider"/>

        <DataTemplate x:Key="CustomerItemTemplate">
            <Border CornerRadius="5" Background="Orange" HorizontalAlignment="Stretch" Padding="5" Margin="3">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Width="Auto">
                    <TextBlock HorizontalAlignment="Stretch">
                    <TextBlock.Text>
                        <MultiBinding StringFormat="{}{0} {1}">
                            <Binding Path="FirstName"/>
                            <Binding Path="LastName"/>
                        </MultiBinding>
                    </TextBlock.Text>
                    </TextBlock>
                </StackPanel>
            </Border>
        </DataTemplate>

    </Window.Resources>

    <Grid>
        <ListBox ItemsSource="{Binding Path=GetAllCustomers, Source={StaticResource TheDataProvider}}"
                 ItemTemplate="{StaticResource CustomerItemTemplate}"/>
    </Grid>
</Window>
役に立ちましたか?

解決

いは複製ができな問題と同一の答えです。

追加 HorizontalContentAlignment="Stretch" おListBox.れています。に注意してくださいとの自動完了です HorizontalAlignment するものとします。

他のヒント

別の解決こちら, かかってしも投稿...

こちらはマーシー-マイルズ選手の答え:

<ListBox.ItemContainerStyle> 
    <Style TargetType="ListBoxItem"> 
        <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter> 
    </Style> 
</ListBox.ItemContainerStyle> 

このためでした。

場合がありま 以上の ListBox, のその他の回答をこちらになるようにの項目 ItemTemplate 残りの ListBox.

に固定した事だったことを今でも覚えていを無効にする水平スクロールバーを、次のように、このコンテナのすべての項目だけにとどの広さで、リストボックス。

そのための修正にListBoxるほどの広さで、リストボックスから、小型化及び必要なストレッチまたは広く、必要な包装は、それぞれ以下の通りです:

<ListBox HorizontalContentAlignment="Stretch" 
         ScrollViewer.HorizontalScrollBarVisibility="Disabled">

(単位のスクロールバーのア)

以降、ボーダー使用だけで、外観をしてしまうのListBoxItemのControlTemplateを修正する件あります。のItemTemplateすのStackPanelのTextBlock.このように、コードまたはクリーンとしての登場で制御する制御してControlTemplateのデータが表示され制御されることになるのDataTemplate.

の修正だったことを今でも覚えている当オフィスビルは長方形を基調 HorizontalAlignment="Stretch"ItemsPresenter 内部 ScrollViewer..

武器agiは、dexで下がらないboxerぐっ...

<Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBox">
                    <ScrollViewer x:Name="ScrollViewer" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}" HorizontalAlignment="Stretch">
                        <ItemsPresenter  Height="252" HorizontalAlignment="Stretch"/>
                    </ScrollViewer>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

また、同じ問題であり、回避策を使ってブレンドをどのくらいのパディングした追加される。私の場合では12日または負の差をなくします。今まで中心であったのに対して適切に

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top