在此示例窗口中,Tabbing through从第一个文本框转到最后一个文本框,然后转到扩展器标题.
<Window x:Class="ExpanderTab.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
FocusManager.FocusedElement="{Binding ElementName=FirstField}">
<StackPanel>
<TextBox TabIndex="10" Name="FirstField"></TextBox>
<Expander TabIndex="20" Header="_abc">
<TextBox TabIndex="30"></TextBox>
</Expander>
<TextBox TabIndex="40"></TextBox>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
显然,我希望这是第一个文本框,扩展器标题,然后是最后一个文本框.有没有一种简单的方法可以将TabIndex分配给扩展器的标头?
我已经尝试强制扩展器使用tabstop KeyboardNavigation.IsTabStop="True"
,但这会使整个扩展器获得焦点,并且整个扩展器不会对空格键做出反应.再过两次选项卡后,再次选择标题,我可以用空格键打开它.
编辑:我会为那些能够提出更清洁方式的人提供奖励 - 如果没有,那么rmoore,你可以拥有代表.谢谢你的帮助.
嗨我正在尝试在设置复选框时在WPF Expander控件的右端放置一个绿色勾号图标.我的代码目前是:
<Expander x:Name="ImageExpander">
<Expander.Header>
<Grid Width="450">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Padding="0">My Header Text</Label>
<Image Grid.Column="1" Margin="0"
Source="C:\...\GreenTick.png" Width="18" />
</Grid>
</Expander.Header>
</Expander>
Run Code Online (Sandbox Code Playgroud)
我使用网格将图标放在扩展器的右上角.这将标题文本放在旋转旁边的常用位置以扩展扩展器.它还在扩展器的右端附近放置了一个450像素的图标.
我希望它没有硬编码,这样无论扩展器有多宽,图标都会保留在右上角.任何人都可以建议如何做到这一点?
我尝试将expandder.header的宽度绑定到扩展器的宽度而没有运气.
谢谢你的建议!
这就是我要的:
1.)当我单击我的Expander按钮并展开它时,它应该延伸到Grid的末尾
见样本图像=>
2.)当我在Expander ScrollBars中的RichTextBox中写入更多文本而不是空格时,必须可见,我应该能够向下滚动.
将滚动查看器放在Expander内容周围并不难,但即使设置"自动"它们也永远不会出现也无济于事.将滚动查看器设置为"可见"我无法滚动,因为扩展器的内容无休止地下降.
这是我的示例代码:
<Grid Margin="30,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<StackPanel Background="LightCoral" Orientation="Horizontal">
<TextBlock Grid.Column="0" Text="Incident type:" VerticalAlignment="Center" />
<ComboBox Grid.Column="1" IsEditable="True" Margin="0,7" Text="{Binding SelectedIncidentReport.IncidentType,Mode=TwoWay}" />
<TextBlock Grid.Column="0" Grid.Row="1" Text="Teachers name:" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="1" Height="25" Text="{Binding SelectedIncidentReport.TeacherName,Mode=TwoWay}" />
<TextBlock Grid.Column="0" Grid.Row="2" Text="Tutor group:" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="2" Margin="0,7" Text="{Binding SelectedIncidentReport.TutorGroup,Mode=TwoWay}" />
</StackPanel>
<Grid Background="LightBlue" Grid.Row="1" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition …
Run Code Online (Sandbox Code Playgroud) 我需要获得WPF Expander.Header的高度,而不是整个Expander只是Header的高度.
没有属性可以获取它,因为Expander.Header + Expander.Content是Expander.Height.
你会怎么做才能获得Expander.Header高度?
出于某种原因,当折叠或扩展时,子项Expander
(放置在StackPanel
另一个内部Expander
)导致父Expander提升其Expanded
或Collapsed
事件.
任何人都知道这是为什么或如何改变它?我只对父母的事件感兴趣.
这是一些测试XAML:
<Expander Header="Outer" Expanded="Expander_Expanded" Collapsed="Expander_Collapsed">
<StackPanel>
<Expander Header="Inner1">
<Canvas Height="100" Width="100" Background="Blue" />
</Expander>
<Expander Header="Inner2">
<Canvas Height="100" Width="100" Background="Red" />
</Expander>
</StackPanel>
</Expander>
Run Code Online (Sandbox Code Playgroud)
这是代码隐藏:
private void Expander_Expanded(object sender, RoutedEventArgs e)
{
MessageBox.Show("expanded");
}
private void Expander_Collapsed(object sender, RoutedEventArgs e)
{
MessageBox.Show("collapsed");
}
Run Code Online (Sandbox Code Playgroud)
当您运行此操作时,如果展开父级,则会获得"扩展"消息框,正如您所期望的那样.但是当你然后展开其中一个孩子时,你会再次收到消息框.
Expanded活动的文档说:
当IsExpanded属性从false更改为true时,会发生Expanded事件
但显然IsExpanded属性在父Expander上没有变化.
为什么会发生这种情况,有什么想法吗?
我在扩展器(存在于wpf窗口的右侧)之前有一个网格分割器,当我运行应用程序时,我需要使用网格分割器在扩展后查看扩展器中的更多数据,但问题是何时我是拖曳分割器我无论原始宽度如何都能看到我的扩展器的全部视图但是在点击扩展器折叠之后它将不会通过保持分割器拖动宽度而转到其原始位置.所以任何人都可以帮助我如何将膨胀机送回原来的位置.
谢谢,@ nagaraju.
使用MVVM.我有一个DataTemplate
用于显示扩展器的扩展器,每个对象都有一些控件.
<DataTemplate>
<Expander ExpandDirection="Down" IsExpanded="False">
<Expander.Header>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="Platform Group {0} {1}">
<Binding Path="PlatformGroupCode"/>
<Binding Path="PlatformGroupName"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Expander.Header>
<vw:PlatformGroup HorizontalAlignment="Left"/>
</Expander>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
在该视图内部是绑定到这2个属性的2个文本框.我IDataErrorInfo
在我的VM中使用进行验证,我在主应用程序资源中使用了一种样式,将错误消息显示为工具提示:
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self},Path=(Validation.Errors).CurrentItem.ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)
添加新组时,2个属性具有默认值,这是无效的,因此我希望文本框为红色以提示用户输入数据.如果Expander的IsExpanded设置为true,则此方法有效.但如果它是假的,我必须扩展并更改其中一个文本框中的值,以便显示红色边框和工具提示.
我不想将扩展器设置为扩展,因为最终会有很多控件.扩展器扩展后如何才能显示红色边框?更好的是,是否有办法使新添加的扩展器扩展(当用户添加新组时,我将PlatformGroupviewModel添加到observablecollection
PlatformGroupviewModel中)?
编辑更多细节:顶级视图:
<StackPanel Orientation="Vertical">
<ScrollViewer VerticalScrollBarVisibility="Auto" MaxHeight="630">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*" />
<ColumnDefinition Width="5*" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" Grid.ColumnSpan="2" Grid.Row="1" HorizontalAlignment="Stretch"> …
Run Code Online (Sandbox Code Playgroud) 我有多个扩展器,我正在寻找一种方法来折叠所有其他扩展器,当其中一个扩展时.我在这里找到了这个解决方案
<StackPanel Name="StackPanel1">
<StackPanel.Resources>
<local:ExpanderToBooleanConverter x:Key="ExpanderToBooleanConverter" />
</StackPanel.Resources>
<Expander Header="Expander 1"
IsExpanded="{Binding SelectedExpander, Mode=TwoWay, Converter={StaticResource ExpanderToBooleanConverter}, ConverterParameter=1}">
<TextBlock>Expander 1</TextBlock>
</Expander>
<Expander Header="Expander 2"
IsExpanded="{Binding SelectedExpander, Mode=TwoWay, Converter={StaticResource ExpanderToBooleanConverter}, ConverterParameter=2}">
<TextBlock>Expander 2</TextBlock>
</Expander>
<Expander Header="Expander 3"
IsExpanded="{Binding SelectedExpander, Mode=TwoWay, Converter={StaticResource ExpanderToBooleanConverter}, ConverterParameter=3}">
<TextBlock>Expander 3</TextBlock>
</Expander>
<Expander Header="Expander 4"
IsExpanded="{Binding SelectedExpander, Mode=TwoWay, Converter={StaticResource ExpanderToBooleanConverter}, ConverterParameter=4}">
<TextBlock>Expander 4</TextBlock>
</Expander>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
public class ExpanderToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (value …
Run Code Online (Sandbox Code Playgroud) 我在Wpf中有一个扩展器.在标题中,我左侧对齐标签,并希望在右侧网站上有一个按钮.我使用以下XAML:
<Expander HorizontalAlignment="Stretch" IsExpanded="True">
<Expander.Header >
<Grid HorizontalAlignment="Stretch" Background="Aqua" Margin="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="Label on the left site"/>
<Button Grid.Column="1" Content="Button on the right"/>
</Grid>
</Expander.Header>
<Label Content="Some Content"/>
</Expander>
Run Code Online (Sandbox Code Playgroud)
但这不起作用.标题中的按钮与标签旁边的左侧对齐.谁能解释我怎么做对了?
expander ×10
wpf ×10
c# ×3
header ×2
mvvm ×2
events ×1
gridsplitter ×1
height ×1
icons ×1
scroll ×1
scrollviewer ×1
stretch ×1
validation ×1
xaml ×1