質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

Q&A

解決済

1回答

5194閲覧

WPF ウィンドウサイズに応じたコントロールの位置調整

退会済みユーザー

退会済みユーザー

総合スコア0

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

1グッド

0クリップ

投稿2020/05/29 05:27

実現したいこと:画面のサイズを大きくしたり小さくしても画面の右上や下にコントロールを固定したい

こまっていること:画面サイズを大きくするとボタンは画面サイズに応じて位置が変わるが小さくすると見切れてしまう(画像参照)イメージ説明

画像のように右上にボタンがあります。画面の右に固定しているはずですが、マインウィンドウを小さくすると見切れます。
どのようにすればずっと固定されたままでいるのでしょうか。

有識者の方いましたらご教示お願い致します。

<Window x:Class="WpfApp2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" Title="MainWindow" AllowsTransparency="True" Background="{x:Null}" ResizeMode="CanResizeWithGrip" Foreground="DarkGray" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" WindowStyle="None"> <DockPanel> <Border Background="Green" BorderThickness="1.5" CornerRadius="10"> <Grid MinWidth="1320" MinHeight="390"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" DockPanel.Dock="Right" ZIndex="4"> <Button Width="30" Height="30" Margin="15,0,0,0" VerticalAlignment="Top" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" Foreground="DarkGray" Content="〇"> </Button> <Button Width="30" Height="30" Margin="0,0,0,0" VerticalAlignment="Top" Background="Transparent" BorderBrush="Transparent" Content="-" BorderThickness="0" Foreground="DarkGray"> </Button> <Button Width="30" Height="30" Margin="0,0,0,0" Padding="0" VerticalAlignment="Top" Content="△" Background="Transparent" BorderBrush="Transparent" Cursor="Hand"> </Button> <Button HorizontalAlignment="Right" Width="30" Height="30" Margin="0,0,0,0" Content="×" Padding="0" VerticalAlignment="Top" Background="Transparent" BorderBrush="Transparent" Cursor="Hand"> </Button> </StackPanel> <Border MinWidth="1310" MinHeight="65" Margin="0,2.5" VerticalAlignment="Top" Background="Blue" BorderThickness="1.5" CornerRadius="10"> <StackPanel VerticalAlignment="Top" Orientation="Horizontal" HorizontalAlignment="Stretch"> <StackPanel Orientation="Horizontal"> <Image Width="65" Height="65" Margin="8,0,0,0"/> <ListView x:Name="ListViewMenu" Height="60" VerticalAlignment="Top" Background="{x:Null}" Cursor="Hand" FontFamily="Arial" FontSize="14" FontWeight="Bold" Foreground="#FFBBB6B6" ScrollViewer.VerticalScrollBarVisibility="Disabled"> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListViewItem"> <Border Background="Transparent"> <ContentPresenter /> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </ListView.ItemContainerStyle> <ListBox.ItemTemplate> <DataTemplate> <TextBlock /> </DataTemplate> </ListBox.ItemTemplate> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListViewItem Name="Dash" Uid="0" Height="60" VerticalAlignment="Center"> <TextBlock Margin="20,0" VerticalAlignment="Center" Text="aaaa" /> </ListViewItem> <ListViewItem Uid="1" Height="65" VerticalAlignment="Center"> <TextBlock Margin="20,0" VerticalAlignment="Center" Text="bbbb" /> </ListViewItem> <ListViewItem Uid="2" Height="65" VerticalAlignment="Center"> <TextBlock Margin="20,0" VerticalAlignment="Center" Text="cccc" /> </ListViewItem> <ListViewItem Uid="4" Height="65" VerticalAlignment="Center"> <TextBlock Margin="20,0" VerticalAlignment="Center" Text="dddd" /> </ListViewItem> <ListViewItem Uid="6" Height="65" VerticalAlignment="Center"> <TextBlock Margin="20,0" VerticalAlignment="Center" Text="fffff" /> </ListViewItem> <ListViewItem Uid="5" Height="65" VerticalAlignment="Center"> <TextBlock Margin="20,0" VerticalAlignment="Center" Text="eeeee" /> </ListViewItem> <ListViewItem Uid="7" Height="65" VerticalAlignment="Center"> <TextBlock Margin="20,0" VerticalAlignment="Center" Text="gggg" /> </ListViewItem> </ListView> </StackPanel> </StackPanel> </Border> <DockPanel Margin="0,65,0,0"> <Frame x:Name="Frame" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DockPanel.Dock="Bottom" Foreground="{x:Null}" NavigationUIVisibility="Hidden" /> </DockPanel> </Grid> </Border> </DockPanel> </Window>
TN8001👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

<Grid MinWidth="1320" MinHeight="390">が原因です。
1320より小さくならないのでGrid内にいるボタン類がWindow外にはみ出ます。

試行錯誤されてxamlに混乱が見られたので、整理させていただきました。
余計なお世話だったらすいません^^;

xml

1<Window 2 x:Class="WpfApp2.MainWindow" 3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 5 xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" 6 Title="MainWindow" 7 Width="1320" 8 Height="390" 9 AllowsTransparency="True" 10 Background="{x:Null}" 11 Foreground="DarkGray" 12 ResizeMode="CanResizeWithGrip" 13 WindowStartupLocation="CenterScreen" 14 WindowStyle="None"> 15 <Window.Resources> 16 <Style x:Key="WindowButtonStyle" TargetType="Button"> 17 <Setter Property="Width" Value="30" /> 18 <Setter Property="Height" Value="30" /> 19 <Setter Property="Margin" Value="0,0,0,0" /> 20 <Setter Property="Background" Value="Transparent" /> 21 <Setter Property="BorderBrush" Value="Transparent" /> 22 <Setter Property="BorderThickness" Value="0" /> 23 </Style> 24 </Window.Resources> 25 <Border 26 Background="Green" 27 BorderThickness="1.5" 28 CornerRadius="10"> 29 <Grid> 30 <Grid.RowDefinitions> 31 <RowDefinition Height="Auto" /> 32 <RowDefinition /> 33 </Grid.RowDefinitions> 34 <StackPanel 35 HorizontalAlignment="Right" 36 VerticalAlignment="Top" 37 Orientation="Horizontal" 38 ZIndex="4"> 39 <Button 40 Content="" 41 Foreground="DarkGray" 42 Style="{StaticResource WindowButtonStyle}" /> 43 <Button 44 Content="-" 45 Foreground="DarkGray" 46 Style="{StaticResource WindowButtonStyle}" /> 47 <Button 48 Padding="0" 49 Content="" 50 Cursor="Hand" 51 Style="{StaticResource WindowButtonStyle}" /> 52 <Button 53 Padding="0" 54 Content="×" 55 Cursor="Hand" 56 Style="{StaticResource WindowButtonStyle}" /> 57 </StackPanel> 58 <Border 59 Margin="0,2.5" 60 VerticalAlignment="Top" 61 Background="Blue" 62 BorderThickness="1.5" 63 CornerRadius="10"> 64 <StackPanel Orientation="Horizontal"> 65 <Image 66 Width="65" 67 Height="65" 68 Margin="8,0,0,0" /> 69 <ListView 70 x:Name="ListViewMenu" 71 Height="60" 72 VerticalAlignment="Top" 73 Background="{x:Null}" 74 Cursor="Hand" 75 FontFamily="Arial" 76 FontSize="14" 77 FontWeight="Bold" 78 Foreground="#FFBBB6B6" 79 ScrollViewer.VerticalScrollBarVisibility="Disabled"> 80 <ListView.ItemContainerStyle> 81 <Style TargetType="ListViewItem"> 82 <Setter Property="Template"> 83 <Setter.Value> 84 <ControlTemplate TargetType="ListViewItem"> 85 <Border Background="Transparent"> 86 <ContentPresenter 87 Margin="20,0" 88 HorizontalAlignment="Center" 89 VerticalAlignment="Center" /> 90 </Border> 91 </ControlTemplate> 92 </Setter.Value> 93 </Setter> 94 </Style> 95 </ListView.ItemContainerStyle> 96 <ListBox.ItemsPanel> 97 <ItemsPanelTemplate> 98 <StackPanel Orientation="Horizontal" /> 99 </ItemsPanelTemplate> 100 </ListBox.ItemsPanel> 101 <ListViewItem Name="Dash" Uid="0"> 102 <TextBlock Text="aaaa" /> 103 </ListViewItem> 104 <ListViewItem Uid="1"> 105 <TextBlock Text="bbbb" /> 106 </ListViewItem> 107 <ListViewItem Uid="2"> 108 <TextBlock Text="cccc" /> 109 </ListViewItem> 110 <ListViewItem Uid="4"> 111 <TextBlock Text="dddd" /> 112 </ListViewItem> 113 <ListViewItem Uid="6"> 114 <TextBlock Text="fffff" /> 115 </ListViewItem> 116 <ListViewItem Uid="5"> 117 <TextBlock Text="eeeee" /> 118 </ListViewItem> 119 <ListViewItem Uid="7"> 120 <TextBlock Text="gggg" /> 121 </ListViewItem> 122 </ListView> 123 </StackPanel> 124 </Border> 125 <Frame 126 x:Name="Frame" 127 Grid.Row="1" 128 Foreground="{x:Null}" 129 NavigationUIVisibility="Hidden" /> 130 </Grid> 131 </Border> 132</Window>

投稿2020/05/29 08:52

編集2023/07/22 07:22
TN8001

総合スコア9357

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2020/05/29 09:35

回答ありがとうございます。解決しました。 コードのレビューまでしていただけるとは、、 おかげ様でいい感じになりました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問