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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何讓ListBox ItemTemplate水平拉伸ListBox的整個(gè)寬度?

如何讓ListBox ItemTemplate水平拉伸ListBox的整個(gè)寬度?

幕布斯6054654 2019-09-19 09:23:49
我希望ListItems以其橙色背景擴(kuò)展為L(zhǎng)istbox的整個(gè)寬度。目前它們只與FirstName + LastName一樣寬。我已將每個(gè)元素設(shè)置為:HorizontalAlignment =“Stretch”。我希望ListboxItems的背景隨著用戶拉伸列表框而擴(kuò)展,因此我不想輸入絕對(duì)值。我需要做什么才能使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貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊

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

添加HorizontalContentAlignment="Stretch"到ListBox。這應(yīng)該夠了吧。只需要小心自動(dòng)完成,因?yàn)樗苋菀?code>HorizontalAlignment被誤解。


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

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊

我在這里找到了另一個(gè)解決方案,因?yàn)槲矣龅搅藘蓚€(gè)帖子......

這是來(lái)自Myles的回答:

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

這對(duì)我有用。


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

TA貢獻(xiàn)1835條經(jīng)驗(yàn) 獲得超7個(gè)贊

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

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

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

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


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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