开发者

WPF contentcontrol loses functionlity after assign null to content

开发者 https://www.devze.com 2022-12-28 11:20 出处:网络
I wrote app with multiple views. Viewmodels are assigned to \"smartcontentcontrol\" which is derived from contentcontrol and overrides contentproperty metadata to handle changed event for that depende

I wrote app with multiple views. Viewmodels are assigned to "smartcontentcontrol" which is derived from contentcontrol and overrides contentproperty metadata to handle changed event for that dependency property. I put some effects on that callback for visuals (renderbitmap and so on). Now i have extended my viewmodel so, that uppon assigning object to smartcontentcotrol content property my viewmodel gets reference to smartcontentcontrol object. I implemented this for my viewmodel to be able to close himself.

So - in xaml I have

<DataTemplate DataType="{x:Type viewmodel:MainViewModel}">
   <view:MainView/>
</DataTemplate>

<SmartContentControl Content="{Binding MainView}"/>

in C# I assign some viewmodel class to that property

MainView = new MainViewModel();
  • at this moment everything goes fine and View appears with right datatemplate. Not only that but my smartcontentcontrol triggers as well - I get cool sliding/fading animation - just what i expected - for example - latter in code calling this

    MainView = null;

slides away "old" view with emptines. So far so good! :) now the tricky part which i can not figure out - As soon as I directly assign to

smartcontentcontrol.content = null

Everything breaks down and as开发者_如何学Pythonsigning to MainView no longer changes view or calls onchanged event. It seems like data binding is gone. WHY is that so? How do I workaround this problem?

0

精彩评论

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