开发者

Disable a button while a DomainContext IsLoading

开发者 https://www.devze.com 2023-02-17 19:37 出处:网络
I have a button on a form which I want to be disabled as long as my DomainDataSource\'s DataContext.IsLoading is true; I want to bind the IsEnabled property of the button to a ! condition on DomainCon

I have a button on a form which I want to be disabled as long as my DomainDataSource's DataContext.IsLoading is true; I want to bind the IsEnabled property of the button to a ! condition on DomainContext.IsLoading and unfortunately I do not know how to handle it as a conditional expression. I can get it working in the reverse of my intended fashion, but not the way I want it to be.

My question is, how do I make this:

<Button IsEnabled="{Binding ElementName=someDomainDataSource, Path=DomainContext.IsLoadi开发者_如何学Gong}" />

effectively be a ! condition along the lines of (this of course does not work) this:

<Button IsEnabled="{Binding ElementName=someDomainDataSource, Path=!DomainContext.IsLoading}" />


You could use a ValueConverter for this, something like an BooleanInverter which on conversion, inverts the value. See MSDN

Your binding would then be

 <Button IsEnabled="{Binding ElementName=someDomainDataSource, Path=DomainContext.IsLoading, Converter={StaticResource BooleanInverter}}" />
0

精彩评论

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