从另一个窗口更改XAML窗口中元素的名称
我有一个主要的xaml窗口,在WPF Expression Blend应用程序中有一个按钮和一个矩形。
当我按下按钮时,将通过以下代码打开一个新窗口:
Private Sub btnCreateProject_Click(ByVal sender as Object,ByVal e as System.Windows.RoutedEventArgs)
Dim impPref As ImportPreferences = new ImportPreferences()
impPref.Show
End Sub
新窗口也有一个按钮。当我按下它时,我想更改NAME的名称主页面的矩形元素。
我用一个用户控件将一个属性放在矩形的名称上。
有任何想法吗???
I have a main xaml window with a button and a rectangle in a WPF Expression Blend Application.
When i press the button, a new window opens by the code below:
Private Sub btnCreateProject_Click(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs)
Dim impPref As ImportPreferences = new ImportPreferences()
impPref.Show
End Sub
The new window has a button too.When i press it, i want to change the NAME of the rectangle element of the main page.
I put a Property to the name of the rectangle by using a user control for it.
Any ideas to do that???
你是在改变矩形的颜色还是类似的东西......如此......如果你已经给了在应用程序的设计时间中命名,即使在读取name属性时更改了实际名称,该名称仍将保持相同。
您可以使用标记属性。
或者你可以尝试创建一个re ctangle 在运行时控制...
are you changing color of the rectangle or some thing similar like that....
if you have given the name in design time of the application then that name will remain same even though the actual name is changed when you read the name property....
alternatively you can use the tag property.
or you can try creating a rectangle control during runtime...
private void Button_Click(object sender, RoutedEventArgs e)
{
MyName1.Tag = "MyNameTag2";
MyName1.Name = "MyName2";
MessageBox.Show(MyName1.Name);
MessageBox.Show(MyName1.Tag.ToString());
MyName1.Tag = "MyNameTag3";
MyName1.Name = "MyName3";
MessageBox.Show(MyName1.Name);
MessageBox.Show(MyName1.Tag.ToString());
}
<Rectangle Fill="White" Stroke="Black" Name="MyName1" HorizontalAlignment="Right" Margin="0,144,104,210" Width="96" Tag="MyName1"/>