Silverlight 属性可见性的属性值无效

发布于 2024-10-10 18:51:53 字数 5117 浏览 0 评论 0原文

在当前项目中,我必须创建一个基于选项卡的导航。每次我们单击一个模块时,如果尚未创建,就会打开一个新的 TabControl,否则将获得焦点。为了实现这一点,我使用如下代码:

HyperlinkButton link = (sender as HyperlinkButton);
string _name = "TAB_" + link.Name;
TabItem tabItem = (from TabItem item in TabControlID.Items
                   where item.Name.Equals(_name)
                   select item).FirstOrDefault();

if (tabItem == null)
{
    tabItem = new TabItem();
    tabItem.Header = link.Content;
    tabItem.Name = _name;
    tabItem.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
    tabItem.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;

    switch (link.Name.ToString().ToLower())
    {
        case "taclass":
            taClass_List taclass_list = new taClass_List();
            tabItem.Content = taclass_list;
            break;
    }

    TabControlID.Items.Add(tabItem);
    tabItem.UpdateLayout();
    TabControlID.UpdateLayout();
}

TabControlID.SelectedItem = tabItem;

这按预期工作,每个选项卡都有一个关联的UserControl(示例中的taClass_List),其中显示包含数据的网格。我有几个按钮来管理数据:添加新记录、导出到 Excel、打印数据、编辑记录和删除记​​录。 taClass_List 的代码是这样的

public partial class taClass_List : UserControl
{ 
    private CespDomainContext _context = new CespDomainContext();

    /// <summary>
    /// 
    /// </summary>
    public taClass_List()
    {
        InitializeComponent();

        LoadOperation<ta_Class> loadOp = this._context.Load(this._context.GetTa_ClassQuery());
        MainGrid.ItemsSource = loadOp.Entities;
        MainPager.Source = loadOp.Entities;
    }

    /// <summary>
    /// s
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void saveChanges()
    {
        _context.SubmitChanges(OnSubmitCompleted, null);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void rejectChanges()
    {
        _context.RejectChanges();
        CheckChanges();
    }

    /// <summary>
    /// 
    /// </summary>
    private void CheckChanges()
    {
        EntityChangeSet changeSet = _context.EntityContainer.GetChanges();
        bool hasChanges = _context.HasChanges;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="so"></param>
    private void OnSubmitCompleted(SubmitOperation so)
    {
        if (so.HasError)
        {
            MessageBox.Show(string.Format("Submit Failed: {0}", so.Error.Message));
            so.MarkErrorAsHandled();
        }
        CheckChanges();
    }

    (...)

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btAdd_Click(object sender, RoutedEventArgs e)
    {
        taClass_Form objform = new taClass_Form();
        objform.IsTabStop = true;
        objform.IsHitTestVisible = true;
        objform.DataContext = _context;
        objform.UpdateLayout();
        objform.Closed += new EventHandler(objform_Closed);
        objform.Show();
        //MainPage.showWindow(objform);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void objform_Closed(object sender, EventArgs e)
    {
        taClass_Form objform = (taClass_Form)sender;
        if (objform.MainObject != null)
        {
            //MainDataSource.DataView.Add(objform.MainObject);
            //MainDataSource.SubmitChanges();
        }
        objform = null;
    }
}   

当我单击“添加新记录”按钮时,调用 btAdd_Click 函数,出现 Childwindow,但我收到一条错误消息

Invalid attribute value for property Visibility
   at MS.Internal.XcpImports.VisualStateManager_GoToState(Control reference, String StateName, Boolean useTransitions, Boolean& refreshInheritanceContext)
   at System.Windows.VisualStateManager.GoToState(Control control, String stateName, Boolean useTransitions)
   at System.Windows.Controls.ValidationSummary.UpdateCommonState(Boolean useTransitions)
   at System.Windows.Controls.ValidationSummary.ValidationSummary_IsEnabledChanged(Object sender, DependencyPropertyChangedEventArgs e)
   at System.Windows.Controls.Control.OnIsEnabledChanged(Control control, EventArgs args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

taClass_Form 代码是(到目前为止):

public partial class taClass_Form : ChildWindow
{
    public ta_Class MainObject = null;
    public taClass_Form()
    {
        InitializeComponent();
    }

    private void OKButton_Click(object sender, RoutedEventArgs e)
    {
        this.DialogResult = true;
    }

    private void CancelButton_Click(object sender, RoutedEventArgs e)
    {
        this.DialogResult = false;
    }

}

我做错了什么?请帮助我

提前致谢。

In current project, i have to create a tab based navigation. Every time we click a module, a new TabControl opens if not alteady created, else focus. To achieve this i use a code like this:

HyperlinkButton link = (sender as HyperlinkButton);
string _name = "TAB_" + link.Name;
TabItem tabItem = (from TabItem item in TabControlID.Items
                   where item.Name.Equals(_name)
                   select item).FirstOrDefault();

if (tabItem == null)
{
    tabItem = new TabItem();
    tabItem.Header = link.Content;
    tabItem.Name = _name;
    tabItem.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
    tabItem.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;

    switch (link.Name.ToString().ToLower())
    {
        case "taclass":
            taClass_List taclass_list = new taClass_List();
            tabItem.Content = taclass_list;
            break;
    }

    TabControlID.Items.Add(tabItem);
    tabItem.UpdateLayout();
    TabControlID.UpdateLayout();
}

TabControlID.SelectedItem = tabItem;

This is working as expected, every tab has a UserControl associated (taClass_List in sample) where a grid with data is displayed. I have a few buttons to manage data: Add new record, Export to excel, Print data, Edit record and Delete record. The code for taClass_List is this

public partial class taClass_List : UserControl
{ 
    private CespDomainContext _context = new CespDomainContext();

    /// <summary>
    /// 
    /// </summary>
    public taClass_List()
    {
        InitializeComponent();

        LoadOperation<ta_Class> loadOp = this._context.Load(this._context.GetTa_ClassQuery());
        MainGrid.ItemsSource = loadOp.Entities;
        MainPager.Source = loadOp.Entities;
    }

    /// <summary>
    /// s
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void saveChanges()
    {
        _context.SubmitChanges(OnSubmitCompleted, null);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void rejectChanges()
    {
        _context.RejectChanges();
        CheckChanges();
    }

    /// <summary>
    /// 
    /// </summary>
    private void CheckChanges()
    {
        EntityChangeSet changeSet = _context.EntityContainer.GetChanges();
        bool hasChanges = _context.HasChanges;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="so"></param>
    private void OnSubmitCompleted(SubmitOperation so)
    {
        if (so.HasError)
        {
            MessageBox.Show(string.Format("Submit Failed: {0}", so.Error.Message));
            so.MarkErrorAsHandled();
        }
        CheckChanges();
    }

    (...)

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btAdd_Click(object sender, RoutedEventArgs e)
    {
        taClass_Form objform = new taClass_Form();
        objform.IsTabStop = true;
        objform.IsHitTestVisible = true;
        objform.DataContext = _context;
        objform.UpdateLayout();
        objform.Closed += new EventHandler(objform_Closed);
        objform.Show();
        //MainPage.showWindow(objform);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void objform_Closed(object sender, EventArgs e)
    {
        taClass_Form objform = (taClass_Form)sender;
        if (objform.MainObject != null)
        {
            //MainDataSource.DataView.Add(objform.MainObject);
            //MainDataSource.SubmitChanges();
        }
        objform = null;
    }
}   

When i click Add New record button, btAdd_Click function is called, Childwindow appears but i receive an error message

Invalid attribute value for property Visibility
   at MS.Internal.XcpImports.VisualStateManager_GoToState(Control reference, String StateName, Boolean useTransitions, Boolean& refreshInheritanceContext)
   at System.Windows.VisualStateManager.GoToState(Control control, String stateName, Boolean useTransitions)
   at System.Windows.Controls.ValidationSummary.UpdateCommonState(Boolean useTransitions)
   at System.Windows.Controls.ValidationSummary.ValidationSummary_IsEnabledChanged(Object sender, DependencyPropertyChangedEventArgs e)
   at System.Windows.Controls.Control.OnIsEnabledChanged(Control control, EventArgs args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

taClass_Form code is (so far):

public partial class taClass_Form : ChildWindow
{
    public ta_Class MainObject = null;
    public taClass_Form()
    {
        InitializeComponent();
    }

    private void OKButton_Click(object sender, RoutedEventArgs e)
    {
        this.DialogResult = true;
    }

    private void CancelButton_Click(object sender, RoutedEventArgs e)
    {
        this.DialogResult = false;
    }

}

What am i doing wrong? Please help me

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

来世叙缘 2024-10-17 18:51:53

经过更多研究后,我发现问题与 SilverLight Toolkit 主题有关。

我在项目中禁用了主题并且没有更多错误。

谢谢

After some more research, i discovered that problem is related with SilverLight Toolkit Themes.

I disabled theming in project and no more errors.

Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文