在我的用户控件ViewUser
中,组框标题和文本块不显示用户 ID?
主窗口:
private void btnGeneral_Click(object sender, RoutedEventArgs e)
{
ViewUser myusercontrol = new ViewUser();
String id = (String)((Button)sender).Tag;
myusercontrol.UserID = id;
PanelMainContent.Children.Add(myusercontrol);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
string uriUsers = "http://localhost:8000/Service/User";
XDocument xDoc = XDocument.Load(uriUsers);
var sortedXdoc = xDoc.Descendants("User")
.OrderByDescending(x => Convert.ToDateTime(x.Element("TimeAdded").Value));
foreach (var node in xDoc.Descendants("User"))
{
Button btnFindStudent = new Button();
btnUser.Click += this.btnGeneral_Click;
btnUser.Tag = String.Format(node.Element("UserID").Value);
//also tryed btnUser.Tag = node.Element("UserID").Value;
用户控制:
public partial class ViewUser : UserControl
{
public ViewUser()
{
InitializeComponent();
}
private string _user;
public string UserID
{
get { return _userID; }
set { _userID = value; }
}
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
groupBox1.Header = UserID;
textBlock1.Text = UserID;
}
}
}