当Button具有给定宽度(通过它的值)并且Parent div也具有给定宽度时,是否可以在TextBox旁边放置一个Button.最后,TextBox宽度+按钮宽度应该是父div的宽度.
TestExample:
#left
{
float: left;
width: 100%;
}
#right
{
width: auto;
}Run Code Online (Sandbox Code Playgroud)
<div>
<input type="text" id="left"/>
<input type="button" id="right" value="AnyText"/>
</div>Run Code Online (Sandbox Code Playgroud)
谢谢!
我有一个非常奇怪的问题:
我使用这个 XAML 样式:
<Style TargetType="ContextMenu">
<Setter Property="ItemsSource">
<Setter.Value>
<CompositeCollection>
<MenuItem Header="Test"/>
</CompositeCollection>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
它有效,但我的控制台有以下错误:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'MenuItem' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'MenuItem' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')
System.Windows.Data Error: 4 : Cannot find source …Run Code Online (Sandbox Code Playgroud) 我尝试使用 TreeView 显示分层数据,并且我想为不同的子类型设置不同的数据模板。
但问题是,我的风格没有得到应用。
也许这是一个非常简单的错误,但我真的没有找到它。
<TreeView ItemsSource="{Binding List}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:Main}" ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Property1}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:Type2}">
<HierarchicalDataTemplate.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="True"/>
</Style>
</HierarchicalDataTemplate.ItemContainerStyle>
<TextBlock Text="{Binding Property2}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:Type3}">
<HierarchicalDataTemplate.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="False"/>
</Style>
</HierarchicalDataTemplate.ItemContainerStyle>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
Run Code Online (Sandbox Code Playgroud) wpf treeview xaml hierarchicaldatatemplate itemcontainerstyle