#c# #wpf
#c# #wpf
Вопрос:
У меня есть две кнопки переключения, одна во внешнем usercontrol в шаблоне управления tabcontrol
Вот код TabControl
<TabControl Name="ConnectionsTab" BorderThickness="0" Background="White">
<TabControl.Resources>
<Style TargetType="{x:Type TabControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid x:Name="templateRoot" ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="ColumnDefinition0"/>
<ColumnDefinition x:Name="ColumnDefinition1" Width="0"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition x:Name="RowDefinition0" Height="Auto"/>
<RowDefinition x:Name="RowDefinition1" Height="*"/>
</Grid.RowDefinitions>
<WrapPanel Grid.Column="0">
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="30"></ColumnDefinition>
</Grid.ColumnDefinitions>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" materialDesign:ButtonAssist.CornerRadius="10">
<TabPanel x:Name="headerPanel" Background="Transparent" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1" Grid.Column="0"/>
</ScrollViewer>
<Border Height="30" VerticalAlignment="Stretch" BorderBrush="LightGray" BorderThickness="0" Grid.Column="1">
<Grid Margin="0,0,0,0">
<ToggleButton Name="OpenPopupButtonConnectionList" Background="White" BorderBrush="Transparent" VerticalAlignment="Bottom" Height="30" ClickMode="Hover">
<ToggleButton.Style>
<Style TargetType="{x:Type ToggleButton}">
<Setter Property="BorderThickness" Value="0"/>
</Style>
</ToggleButton.Style>
<Grid Margin="0,10,0,0">
<materialDesign:PackIcon Background="White" Foreground="Black" Kind="ArrowDropDown" Height="18" VerticalAlignment="Bottom" Width="18" />
</Grid>
</ToggleButton>
<Popup Name="PresetPopupConnectionList" IsOpen="{Binding ElementName=OpenPopupButtonConnectionList, Path=IsChecked}" PlacementTarget="{Binding ElementName=OpenPopupButtonConnectionList}" AllowsTransparency="True" PopupAnimation="Slide" StaysOpen="False" >
<ListBox Name="ConnectionList" ItemsSource="{Binding Items, RelativeSource={RelativeSource Mode=TemplatedParent}}" Background="White" SelectionChanged="ConnectionList_SelectionChanged" MaxHeight="300" BorderBrush="LightGray" BorderThickness="1" SelectionMode="Single" SelectedIndex="-1">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Header}"></TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Popup>
</Grid>
</Border>
</Grid>
</WrapPanel>
<Border x:Name="contentPanel" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="1" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
<ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="TabStripPlacement" Value="Bottom">
<Setter Property="Grid.Row" TargetName="headerPanel" Value="1"/>
<Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
<Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
<Setter Property="Height" TargetName="RowDefinition1" Value="Auto"/>
<Setter Property="Margin" TargetName="headerPanel" Value="2,0,2,2"/>
</Trigger>
<Trigger Property="TabStripPlacement" Value="Left">
<Setter Property="Grid.Row" TargetName="headerPanel" Value="0"/>
<Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
<Setter Property="Grid.Column" TargetName="headerPanel" Value="0"/>
<Setter Property="Grid.Column" TargetName="contentPanel" Value="1"/>
<Setter Property="Width" TargetName="ColumnDefinition0" Value="Auto"/>
<Setter Property="Width" TargetName="ColumnDefinition1" Value="*"/>
<Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
<Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
<Setter Property="Margin" TargetName="headerPanel" Value="2,2,0,2"/>
</Trigger>
<Trigger Property="TabStripPlacement" Value="Right">
<Setter Property="Grid.Row" TargetName="headerPanel" Value="0"/>
<Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
<Setter Property="Grid.Column" TargetName="headerPanel" Value="1"/>
<Setter Property="Grid.Column" TargetName="contentPanel" Value="0"/>
<Setter Property="Width" TargetName="ColumnDefinition0" Value="*"/>
<Setter Property="Width" TargetName="ColumnDefinition1" Value="Auto"/>
<Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
<Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
<Setter Property="Margin" TargetName="headerPanel" Value="0,2,2,2"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid Background="White">
<Border Name="Border" BorderBrush="#1b9ed2" Margin="6,0,12,0" Background="White">
<ContentPresenter Height="30" x:Name="ContentSite" ContentSource="Header" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="5,15,5,-5">
</ContentPresenter>
</Border>
<Button Background="Transparent" BorderBrush="Transparent" Name="TabCloseButton" Click="TabCloseButton_Click" HorizontalAlignment="Right" VerticalAlignment="Bottom" ToolTip="Close" HorizontalContentAlignment="Right" Padding="0">
<materialDesign:PackIcon Kind="Close" Foreground="Gray" HorizontalAlignment="Right"/>
</Button>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="TabIndex" Value="0">
<Setter TargetName="TabCloseButton" Property="Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="DemiBold" />
<Setter TargetName="Border" Property="BorderThickness" Value="0,0,0,2"/>
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="Border" Property="BorderThickness" Value="0,0,0,0"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="FontWeight" Value="DemiBold" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="FontSize" Value="12"/>
</Style>
</TabControl.Resources>
</TabControl>
Я добавил другой пользовательский элемент управления в connectionspage в качестве первого элемента tabitem
public ConnectionsPage(PMPResponse response)
{
this.response = response;
InitializeComponent();
tabItems.Add(new TabItem { Header = "Connections", Content = new ResourceAccountDisplayUserControlCopy(response), TabIndex = 0 });
ConnectionsTab.ItemsSource = tabItems;
ConnectionsTab.SelectedIndex = 0;
LoadResourceUserControl();
}
У меня есть еще одно всплывающее окно внутри внутреннего usercontrol
<Grid>
<ToggleButton Name="OpenPopupButtonUserProfile" Background="Transparent" BorderBrush="Transparent" Height="20" VerticalAlignment="Center" Width="20">
<ToggleButton.Style>
<Style TargetType="{x:Type ToggleButton}">
<Setter Property="BorderThickness" Value="0"/>
</Style>
</ToggleButton.Style>
<materialDesign:PackIcon Background="White" Foreground="Black" Kind="ArrowDropDown" Height="18" VerticalAlignment="Center" Width="18" />
</ToggleButton>
<Popup Name="PresetPopupSort" IsOpen="{Binding ElementName=OpenPopupButtonUserProfile, Path=IsChecked}" PlacementTarget="{Binding ElementName=OpenPopupButtonUserProfile}" AllowsTransparency="True" PopupAnimation="Slide" StaysOpen="False" >
<ListBox Background="White" HorizontalContentAlignment="Center" BorderBrush="LightGray" BorderThickness="0.5" Margin="15,0,15,0" Padding="5">
<ListBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
<Style TargetType="ListBoxItem">
</Style>
</ListBox.Resources>
<ListBoxItem Height="25" Padding="5,0,5,0">
<Button Height="20" Padding="0" Name="SortAscending" Click="SortAscending_Click" Background="Transparent" BorderBrush="Transparent" Foreground="Gray">Ascending</Button>
</ListBoxItem>
<Separator Height="0.5" Margin="-8,2,-7.6,2"/>
<ListBoxItem Height="25" Padding="5,0,5,0">
<Button Height="20" Padding="0" Name="SortDescending" Click="SortDescending_Click" Background="Transparent" BorderBrush="Transparent" Foreground="Gray">Descending</Button>
</ListBoxItem>
</ListBox>
</Popup>
</Grid>
Когда я нажимаю кнопку переключения внутреннего usercontrol, появляется всплывающее окно, когда я нажимаю внешнюю кнопку переключения, появляется всплывающее окно.
Но как только нажата внешняя кнопка переключения. при нажатии на внутреннюю кнопку переключения всплывающее окно внутри внутреннего usercontrol не отображается. но внутренняя кнопка переключения возвращает true . Кнопка переключения проверяется при нажатии на внешнюю кнопку переключения, оба всплывающих окна отображаются одновременно.
Я не знаю, что я делаю не так.
Комментарии:
1. Дважды проверьте опубликованный вами код. Первый раздел не имеет смысла, так как у вас есть
Setter
непосредственно внутриTabControl.Resources
.2. @KeithStein Извини братан, что я пропустил строку при вставке <Style TargetType=»{x:Type TabControl}»> Now i have edited the question.