【问题标题】:To display a value in Silverlight website based on its database table column value根据其数据库表列值在 Silverlight 网站中显示值
【发布时间】:2020-02-10 06:44:00
【问题描述】:

我有一个数据库表,其中有一个名为 Status 的列,“Status”列中的值将是 1 或 0 或 Null。我想要实现的是,如果值为 1,则应显示 On,如果值为 0,则应显示 Off,如果值为 null,则应显示。这是我到目前为止尝试过的一些 sn-p,我无法弄清楚如何根据表列值显示结果。我附上了数据库的示例输出。请提供一些在这种情况下可能对我有用的想法
Output Display

#Accessing table value
public IQueryable<MSDS_VII> GetMSDS()
{
    return (
        from r in this._context.MSDS_VII
        orderby r.NO
        select r);
}

#Creating ria service
   public void GetMSDS(Action<CustomLoadOperation<MSDS_VII>> loadCompleted, object 
   userState = null, int pageSize = 20)
    {
        new CustomDataAdapter<MSDS_VII>(this.client, this.client.GetMSDSQuery(), this.client.MSDS_VIIs, pageSize, loadCompleted, userState);
    }

#View Model
public class MSDSStatusViewModel : BaseViewModel
{

    [ImportingConstructor]
    public MSDSStatusViewModel(IWindowManager windowManager, IEventAggregator eventAggregator, DomainServiceClient service)
        : base()
    {
        this.windowManager = windowManager;
        this.service = service;
        this.eventAggregator = eventAggregator;
        this.DisplayName = "MSDS VII Status";
    }

    public DomainCollectionView<MSDS_VII> msdsList;
   
    public DomainCollectionView<MSDS_VII> MSDSList
    {
        get
        {
            return this.msdsList;
        }
        set
        {
            this.msdsList = value;
            this.NotifyOfPropertyChange(() => MSDSList);
        }
    }


    public override void GetData()
    {
        this.service.GetMSDS(this.OnGeneralItemsLoadCompleted<MSDS_VII>);
    }

    public override void OnGeneralItemsLoadCompleted<TEntity>(CustomLoadOperation<TEntity> result)
    {
        base.OnGeneralItemsLoadCompleted(result);
        if (result.Result.IsComplete)
        {
            if (typeof(TEntity).Equals(typeof(MSDS_VII)))
            {
                MSDSList = result.CollectionView as DomainCollectionView<MSDS_VII>;                      
            }
        }
    }

#View xaml code
<c1:C1FlexGrid Grid.Row="1" ItemsSource="{Binding MSDSList}"  AutoGenerateColumns="False" HeadersVisibility="Column" GroupRowPosition="BelowData" MaxColumnWidth="500" c1:LicenseMode.Evaluation="True">
        <c1:C1FlexGrid.Columns>
           <c1:Column Binding="{Binding NO}" Header="NO."Width="70" />
           <c1:Column Binding="{Binding ITEM}" Header="Item" Width="400"  />
           <c1:Column Binding="{Binding STATUS}" Header="Status" Width="130" />
        </c1:C1FlexGrid.Columns>
 </c1:C1FlexGrid>

【问题讨论】:

    标签: c# mvvm wcf-ria-services silverlight-5.0


    【解决方案1】:

    您需要创建一个自定义转换器来将值转换为适合控件的值,反之亦然。网上有很多例子。我在快速搜索后找到了这个,应该对你有帮助。IValueConvertor

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 1970-01-01
      • 1970-01-01
      • 2011-04-23
      • 2018-02-03
      • 1970-01-01
      相关资源
      最近更新 更多