开发者

Silverlight Invalid attribute value for property Visibility

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 = 开发者_StackOverflow_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.


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

I disabled theming in project and no more errors.

Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜