現在、アプリケーション上で画面レイアウトの設定をGUIで変更する仕組みを実装しています。
ちょっと分かりにくいかもしれませんが。
画像のようなパネルを表示して、パネルの境界線をドラッグすることで①と②のサイズを変更して、
それぞれのパネルのサイズをファイルに保存するというものを考えています。
このパネルはユーザーコントロールを定義して、GridとGridSplitterを使っています。
依存関係プロパティも定義しており、外部からパネルの幅と高さをBindできるようにはしてあります。
この外部からBindされた値(変数)をどのように使用したら考えているような動作になるか分からず困っています。
理想はGridSplitterを動かせばBindされた変数にサイズの変わったGridの幅がそのままBind元に行くというのをイメージしているのですが、
Bindした変数の値が変わらないため、おかしな見た目になってしまいます。
どのようにすればいいか教えていただけないでしょうか?
下記に現在のソースを書いておきます。
日本語がおかしな部分があるかもしれません、足りない情報があれば指摘していただければすぐに追加いたしますので、
よろしくお願いいたします。
XAML
1 <Grid> 2 <Grid.ColumnDefinitions> 3 <ColumnDefinition Width="*"/> 4 <ColumnDefinition Width="1"/> 5 <ColumnDefinition Width="*"/> 6 </Grid.ColumnDefinitions> 7 8 <Grid Grid.Column="0" Background="Red" HorizontalAlignment="Stretch" Width="{Binding Panel1Width, ElementName=root}" > 9 <TextBlock Text="①" TextAlignment="Center" VerticalAlignment="Center" FontSize="30" FontWeight="UltraBold"/> 10 </Grid> 11 12 <Grid Grid.Column="2" Background="Blue" HorizontalAlignment="Stretch" Width="{Binding Panel2Width, ElementName=root}"> 13 <TextBlock Text="②" TextAlignment="Center" VerticalAlignment="Center" FontSize="30" FontWeight="UltraBold"/> 14 </Grid> 15 16 <GridSplitter Grid.Column="1" ResizeDirection="Columns" HorizontalAlignment="Stretch"/> 17 </Grid>
C#
1 public partial class Layout2Panel : UserControl 2 { 3 public Layout2Panel() 4 { 5 InitializeComponent(); 6 } 7 8 public double Panel1Width 9 { 10 get => (double)GetValue(Panel1WidthProperty); 11 set => SetValue(Panel1WidthProperty, value); 12 } 13 public static readonly DependencyProperty Panel1WidthProperty = 14 DependencyProperty.Register( 15 "Panel1Width", 16 typeof(double), 17 typeof(Layout2Panel), 18 new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); 19 20 public double Panel1Height 21 { 22 get => (double)GetValue(Panel1HeightProperty); 23 set => SetValue(Panel1HeightProperty, value); 24 } 25 public static readonly DependencyProperty Panel1HeightProperty = 26 DependencyProperty.Register( 27 "Panel1Height", 28 typeof(double), 29 typeof(Layout2Panel), 30 new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); 31 32 public double Panel1X 33 { 34 get => (double)GetValue(Panel1XProperty); 35 set => SetValue(Panel1XProperty, value); 36 } 37 public static readonly DependencyProperty Panel1XProperty = 38 DependencyProperty.Register( 39 "Panel1X", 40 typeof(double), 41 typeof(Layout2Panel), 42 new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); 43 44 public double Panel1Y 45 { 46 get => (double)GetValue(Panel1YProperty); 47 set => SetValue(Panel1YProperty, value); 48 } 49 public static readonly DependencyProperty Panel1YProperty = 50 DependencyProperty.Register( 51 "Panel1Y", 52 typeof(double), 53 typeof(Layout2Panel), 54 new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); 55 56 public double Panel2Width 57 { 58 get => (double)GetValue(Panel2WidthProperty); 59 set => SetValue(Panel2WidthProperty, value); 60 } 61 public static readonly DependencyProperty Panel2WidthProperty = 62 DependencyProperty.Register( 63 "Panel2Width", 64 typeof(double), 65 typeof(Layout2Panel), 66 new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); 67 68 public double Panel2Height 69 { 70 get => (double)GetValue(Panel2HeightProperty); 71 set => SetValue(Panel2HeightProperty, value); 72 } 73 public static readonly DependencyProperty Panel2HeightProperty = 74 DependencyProperty.Register( 75 "Panel2Height", 76 typeof(double), 77 typeof(Layout2Panel), 78 new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); 79 80 public double Panel2X 81 { 82 get => (double)GetValue(Panel2XProperty); 83 set => SetValue(Panel2XProperty, value); 84 } 85 public static readonly DependencyProperty Panel2XProperty = 86 DependencyProperty.Register( 87 "Panel2X", 88 typeof(double), 89 typeof(Layout2Panel), 90 new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); 91 92 public double Panel2Y 93 { 94 get => (double)GetValue(Panel2YProperty); 95 set => SetValue(Panel2YProperty, value); 96 } 97 public static readonly DependencyProperty Panel2YProperty = 98 DependencyProperty.Register( 99 "Panel2Y", 100 typeof(double), 101 typeof(Layout2Panel), 102 new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); 103 } 104

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/08/20 16:02
2021/08/23 01:12