Silverlight属性Visibility的属性值无效

时间:2011-01-06 10:33:13

标签: silverlight c#-4.0 childwindow

在当前项目中,我必须创建基于选项卡的导航。每次我们点击一​​个模块时,如果没有创建,则会打开一个新的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;
    }

}

我做错了什么?请帮帮我

提前致谢。

1 个答案:

答案 0 :(得分:0)

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

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

由于