实际上,我正在使用带有WPF的C#。让我再解释一下:
我使用一个按钮创建UserControl(WPF)(单击按钮创建图像和文本框(如新文件夹))。
我有另一个带有Button的Window窗体(WPF),我想在Window窗体中单击按钮来在UserControl中执行Action而不是Button。以下是UserControl的代码:
private void btnNewRoom_Click(object sender, RoutedEventArgs e)
{
Image img = new Image();
img.VerticalAlignment = System.Windows.VerticalAlignment.Top;
img.Width = 100;
img.Height = 100;
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
var applicationDirectory = System.IO.Path.GetDirectoryName(assemblyLocation);
img.Source = new BitmapImage(new Uri("/Resources/Images/folder.png", UriKind.RelativeOrAbsolute));
StackPanel sp = new StackPanel();
TextBox tb = new TextBox();
tb.Width = 120;
tb.Height = 25;
tb.Text = "New Folder";
sp.Children.Add(img);
sp.Children.Add(tb);
AddNewRoom.Children.Add(sp);
}
并且有可能吗?
注意:点击按钮创建图像和文本框的任何好方法吗?
答案 0 :(得分:0)
在WPF控件中实现静态事件处理程序,只需从Window窗体的按钮单击事件中调用它。