简体   繁体   English

如何使Caliburn.Micro ViewModel的文本框为ReadOnly?

[英]How to make textbox ReadOnly from Caliburn.Micro ViewModel?

I started programming app on WP 7.1 with Caliburn.Micro. 我开始使用Caliburn.Micro在WP 7.1上编写应用程序。 My starting view is a logging window with login and pass textboxes and button with log in action. 我的初始视图是带有登录和传递文本框以及带有登录操作的按钮的日志记录窗口。 Now I want to show progress bar on the top as indeterminate and make textboxes as readOnly. 现在,我想在顶部将进度条显示为不确定,并将文本框显示为readOnly。 I have been searching in the web and found only not satisfacting me solutions. 我一直在网上搜索,发现只有不满意的解决方案。 I am thinking about solutions like this: 我正在考虑这样的解决方案:

  1. Change default binder to bind properties by convention like "ControlNameIsReadOnly" "ControlNameIsEnabled" 更改默认联编程序以按约定绑定属性,例如“ ControlNameIsReadOnly”,“ ControlNameIsEnabled”
  2. Make screen as dialog box with only progress bar shown 将屏幕设为对话框,仅显示进度条

Anybody has resolved this? 有人解决了吗? None of those solutions are satisfacting me. 这些解决方案都没有令我满意。

There are a few ways - depends if you want to do it convention based and per-control 有几种方法-取决于是否要基于约定和按控件进行

Without conventions you could use a busy property eg 没有约定,您可以使用繁忙的属性,例如

class SomeViewModel : Screen // or whatever
{
    public bool IsBusy 
    {
        get { // getter code 
        } 
        set { // setter code, calling notifypropertychanged 
        }

}

Then in your control 然后由您掌控

<UserControl>
    <Grid>
        <TextBox>Hello World</TextBox>
        <Border Background="#AAFFFFFF"> <!-- Semitransparent overlay -->
            <ProgressBar IsIndeterminate="true" Visibility="{Binding IsBusy, Converter={StaticResource BooleanToVisibilityConverter}" />
        </Border>
    </Grid>
</UserControl>

Your converter may look like this: 您的转换器可能如下所示:

class BooleanToVisibilityConverter : IValueConverter
{
    public void Convert(object value, blah blah blah...)
    {
        if(value is bool)
        {
            if((bool)value) return Visibility.Visible;

            return Visibility.Collapsed;
        }

        return null;
    }
}

This way you can overlay the progressbar when things are happening on your control so the user cannot interact. 这样,当控件上发生任何事情时,您可以覆盖进度条,以便用户无法进行交互。

You may have to tweak for best fit as I've not tested any of that :P 您可能需要调整以使其最适合,因为我还没有测试过任何一个:P

You can even bind IsReadOnly on the textboxes to the IsBusy property. 您甚至可以将文本框上的IsReadOnly绑定到IsBusy属性。 This is of course assuming you don't mind doing it the non-conventional method and that it all works on Windows Phone 7 :) 当然,这是假设您不介意使用非常规方法,并且所有方法都可以在Windows Phone 7上使用的:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM