WPF GetValue

Site Index




<Canvas Height="500" Width="780">
<Grid Height="500" Width="780">
<Grid.RowDefinitions>
<RowDefinition Height="10" />
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10" />
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<DataGrid AutoGenerateColumns="True" Grid.Column="2" Grid.Row="2" Margin="3" Name="dataGrid1" />
<Button Content="Set" Grid.Column="2" Grid.Row="1" Margin="3" Name="button_Set" Click="button_Set_Click" />
<Canvas Grid.Column="1" Grid.Row="2" Margin="3" Name="xaml_canvas1" Background="Black">
<Button Canvas.Left="275" Canvas.Top="182" Content="999" Height="25" Name="button999" Width="30" Background="Yellow"/>
</Canvas>
</Grid>
</Canvas>




private void proc_set_button()
{
for (int idx = 0; idx < 4; idx++)
{
z_tag_Button[idx] = new Button();
z_tag_Button[idx].Width = 30;
z_tag_Button[idx].Height = 25;
z_tag_Button[idx].Content = idx;
xaml_canvas1.Children.Add(z_tag_Button[idx]);
}
//***********************************
// ボタン位置取得 (canvas内)
//***********************************
double w_left_999 = Convert.ToDouble(button999.GetValue(Canvas.LeftProperty));
double w_top_999 = Convert.ToDouble(button999.GetValue(Canvas.TopProperty));

z_tag_Button[0].SetValue(Canvas.LeftProperty, w_left_999);
z_tag_Button[0].SetValue(Canvas.TopProperty, 100.0);

z_tag_Button[1].SetValue(Canvas.LeftProperty, 100.0);
z_tag_Button[1].SetValue(Canvas.TopProperty, w_top_999);
//***********************************
// 暗黙値は普通には取得不能
//***********************************
double w_canvas_height = Convert.ToDouble(xaml_canvas1.GetValue(HeightProperty));
double w_canvas_width = Convert.ToDouble(xaml_canvas1.GetValue(WidthProperty));
z_tag_Button[2].SetValue(Canvas.LeftProperty, w_canvas_width / 2);
z_tag_Button[2].SetValue(Canvas.TopProperty, w_canvas_height / 2);
//***********************************
// ボトムからの位置指定
//***********************************
z_tag_Button[3].SetValue(Canvas.LeftProperty, 450.0);
z_tag_Button[3].SetValue(Canvas.BottomProperty, 150.0);
}




AX