第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何讓ListBox ItemTemplate水平拉伸ListBox的整個寬度?

如何讓ListBox ItemTemplate水平拉伸ListBox的整個寬度?

幕布斯6054654 2019-09-19 09:23:49
我希望ListItems以其橙色背景擴展為Listbox的整個寬度。目前它們只與FirstName + LastName一樣寬。我已將每個元素設(shè)置為:HorizontalAlignment =“Stretch”。我希望ListboxItems的背景隨著用戶拉伸列表框而擴展,因此我不想輸入絕對值。我需要做什么才能使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>
查看完整描述

3 回答

?
慕容森

TA貢獻1853條經(jīng)驗 獲得超18個贊

我確定這是重復(fù)的,但我找不到同樣答案的問題。

添加HorizontalContentAlignment="Stretch"到ListBox。這應(yīng)該夠了吧。只需要小心自動完成,因為它很容易HorizontalAlignment被誤解。


查看完整回答
反對 回復(fù) 2019-09-19
?
FFIVE

TA貢獻1797條經(jīng)驗 獲得超6個贊

我在這里找到了另一個解決方案,因為我遇到了兩個帖子......

這是來自Myles的回答:

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

這對我有用。


查看完整回答
反對 回復(fù) 2019-09-19
?
qq_花開花謝_0

TA貢獻1835條經(jīng)驗 獲得超7個贊

如果你的物品比那些物品ListBox,那么這里的其他答案也無濟于事:物品中的物品ItemTemplate仍然寬于ListBox。

對我有用的修復(fù)是禁用水平滾動條,顯然,它還告訴容器所有這些項目只保留與列表框一樣寬。

因此,獲得與列表框一樣寬的ListBox項目的組合修復(fù),無論它們是否更小并且需要拉伸,還是更寬并需要包裝,如下所示:

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


查看完整回答
反對 回復(fù) 2019-09-19
  • 3 回答
  • 0 關(guān)注
  • 922 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號