亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

如何將Combobox下拉列表的寬度設置為它所屬的Combobox?

如何將Combobox下拉列表的寬度設置為它所屬的Combobox?

C#
肥皂起泡泡 2022-11-21 16:25:04
見下圖,如何將下拉列表邊框與實際的組合框對齊?https://imgur.com/uNO45F2這是 Combobox 的代碼,它使用自定義的 ComboBoxItem 樣式,<ComboBox Grid.Row="0" Grid.Column="0" ItemsSource="{Binding ASDevicesView, Mode=OneWay , UpdateSourceTrigger=PropertyChanged}"  AutomationProperties.AutomationId="4314"                      SelectedItem="{Binding SDevice}" IsEditable="True" Text="{Binding SearchText}" MaxDropDownHeight="166" ItemContainerStyle="{StaticResource MyComboBoxItemStyle}">    <ComboBox.Style>        <Style TargetType="{x:Type ComboBox}">            <Style.Triggers>                <Trigger Property="IsKeyboardFocusWithin" Value="True">                    <Setter Property="IsDropDownOpen" Value="true" />                </Trigger>            </Style.Triggers>        </Style>    </ComboBox.Style></ComboBox>這是 ComboBoxItem 樣式的代碼,<Style x:Key="MyComboBoxItemStyle" BasedOn="{StaticResource {x:Type ComboBoxItem}}" TargetType="{x:Type ComboBoxItem}">    <Setter Property="HorizontalContentAlignment" Value="Center" />    <Setter Property="VerticalContentAlignment" Value="Center" />    <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled" />    <Setter Property="Width" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualWidth}" />    <Setter Property="Height" Value="40" />
查看完整描述

1 回答

?
開滿天機

TA貢獻1786條經驗 獲得超13個贊

我認為問題是 theComboBox不是 theTemplatedParentComboBoxItem(實際上有人指出,例如在這個評論中),所以最好明確地搜索它:

<Setter Property="Width" Value="{Binding 
    RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}, Path=ActualWidth}" />


查看完整回答
反對 回復 2022-11-21
  • 1 回答
  • 0 關注
  • 92 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號