Changing Styles using ImplicitStyleManager-2

In an earlier post we saw it was easy to change styles using ImplicitStyleManager. But TabControl and DataGrid were not used in the sample. Looks like we need to do some additional work to get that to work.

I modified the sample to include a DataGrid, TabControl and DataGrid nested inside a TabControl

Tha change is we have to add a LayoutUpdated eventhandler and have logic like this to set the styles for tabcontrol1 and datagrid2 which is nested inside the tabcontrol

 void Demo_LayoutUpdated(object sender, EventArgs e)
            ImplicitStyleManager.SetApplyMode(tabcontrol1, ImplicitStylesApplyMode.Auto);

            ImplicitStyleManager.SetApplyMode(datagrid2, ImplicitStylesApplyMode.Auto);

you can comment these lines in the above event handler and see the styles are not going to be applied.

if you download the code and run it without any changes and change the style few times. it will start giving random errors. Try refreshing the application and use the same style again(it will work, but fail on some other style).

I am not sure why I get those errors

you can download the code here


7 thoughts on “Changing Styles using ImplicitStyleManager-2

  1. Hi,lee_sl

    Thank you very much for you samples.But i still have issues in my case.

    I found you use *.xaml file(ExpressionDark.xaml…..) to style the controls.

    But i use the *.dll file (Microsoft.Windows.Controls.Theming.ExpressionDark.dll) and add the inside of mydatagrid.

    I also add the LayoutUpdated event you wrote, but still failed.

    any suggustions?


  2. AK,
    sorry, I am not sure what is going on. I tried to include ShinyBlue.xaml inthe project and reference that. I was still getting a similar error like I mentioned in the post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s