/ / Jak dokładnie rozciągnąć Kontrolę menu do TabHeader w WPF? - c #, wpf, vb.net, xaml

Jak dokładnie rozciągnąć Kontrolę menu do TabHeader w WPF? - c #, wpf, vb.net, xaml

Poniższy kod XAML służy do Twoich potrzeb testowych.

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="MainWindow" Title="MainWindow"
Height="200" Width="300">

<Grid>
<TabControl>
<TabItem Height="40" Width="50" Margin="0" Padding="0">
<TabItem.Header>
<Menu Height="40" Width="50" Margin="0" Padding="0">
<MenuItem Height="40" Width="50" Header="File" Margin="0" Padding="0" Background="Red">
<MenuItem Header="About"/>
<MenuItem Header="Help"/>
<MenuItem Header="Print"/>
</MenuItem>
</Menu>
</TabItem.Header>
<Label Content="No content here because this Tab will not use."/>
</TabItem>
<TabItem Height="40" Width="50" Header="Spain" IsSelected="True">
<Label Content="Some content for Spain"/>
</TabItem>
<TabItem Height="40" Width="50" Header="France">
<Label Content="Some content for France"/>
</TabItem>
<TabItem Height="40" Width="50" Header="Italy">
<Label Content="Some content for Italy"/>
</TabItem>
</TabControl>
</Grid>
</Window>

Pytanie Zdjęcie: https://prnt.sc/imvkfk

Próbowałem użyć linku, ale nie działa.

http://www.techerator.com/2011/05/how-to-stretch-a-menu-control-to-the-width-of-a-window-in-wpf/

P.S. Chcę dokładnego rozciągnięcia. Chcę, aby użytkownik nie był w stanie kliknąć TabHeader za pomocą myszy.

Odpowiedzi:

1 dla odpowiedzi № 1

Myślę, że jestem nieco zdezorientowany tym, kim jesteśpróbując osiągnąć spokój, ale czy próbujesz czegoś takiego? Zastąp kod tego pierwszego TabItem tym. Daj mi znać, jeśli tego chcesz. Jeśli nie jest to tylko dalsze wyjaśnienie i możemy wprowadzić poprawki.

<TabItem Height="40" Width="50" Margin="-3" Padding="0">
<TabItem.Header>
<Grid  Height="100" Width="100">
<Menu Margin="0" Padding="0">
<MenuItem Header="File" Margin="0" Padding="0" Background="Red">
<MenuItem Header="About"/>
<MenuItem Header="Help"/>
<MenuItem Header="Print"/>
</MenuItem>
</Menu>
</Grid>

</TabItem.Header>
<Label Content="No content here because this Tab will not use."/>
</TabItem>

Po prostu zapakowałem Twoje menu w siatkę, aby uzyskać trochę więcej kontroli.