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}" ?
精彩评论