【发布时间】:2015-01-06 16:35:32
【问题描述】:
我的页面中有以下内容:
<ContentPage.ToolbarItems>
<ToolbarItem Text="Run" Command="{Binding RunCommand}" />
</ContentPage.ToolbarItems>
该命令启动异步任务。 只要异步任务仍在运行,我就尝试通过将其绑定到布尔属性来禁用控件,如下所示:
<ContentPage.ToolbarItems>
<ToolbarItem Text="Run" Command="{Binding RunCommand}" IsEnabled="{Binding MyBoolProperty}" />
</ContentPage.ToolbarItems>
我的问题是 ToolbarItem 似乎没有“IsEnabled”属性。有没有办法使用 Xamarin.Forms 实现我想要做的事情?
【问题讨论】:
-
注意,我尝试用“Button”替换“ToolbarItem”,结果惨遭失败:“Object type Xamarin.Forms.Button cannot be convert to target type: Xamarin.Forms.ToolbarItem”。
-
如果您在 UI 线程上运行它,则取决于您的操作的预期长度,按钮保持按下状态。这是一个丑陋的黑客,你不应该将它用于网络访问,因为这会锁定你的应用很长时间
-
也许源已经更新,但现在有一个
IsEnabledproperty。不过,我仍然无法更改设置后的值。
标签: c# xaml xamarin xamarin.forms