开发者

How to define a ListBoxItem Template that has the same size of its parent?

开发者 https://www.devze.com 2022-12-27 16:54 出处:网络
I am using the following code: <ListBox x:Name=\"lbItems\" Grid.Row=\"1\" Margin=\"2\"> <ListBox.Template>

I am using the following code:

<ListBox 
    x:Name="lbItems"            
    Grid.Row="1"
    Margin="2">
    <ListBox.Template>
        <ControlTemplate>
            <Border 
                Background="{StaticResource DarkerBrush}"                            
                Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type ListBox}, Mode=FindAncestor}}"
                BorderBrush="{StaticResource MediumBrush}"
                BorderThickness="0"
                CornerRadius="4">
                <ItemsPresenter />                            
            </Border>
        </ControlTemplate>
    </ListBox.Template>
</ListBox>

it wo开发者_运维知识库rks, but I see an exception in the Output Window that I would like to remove.

System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=ActualWidth; DataItem=null; target element is 'Border' (Name=''); target property is 'Width' (type 'Double')

Probably I am doing something not perfectly right, so do you have any idea how can I improve my code?


Width="{Binding ElementName=lbItems, Path=ActualWidth}" ?
0

精彩评论

暂无评论...
验证码 换一张
取 消