使用Telerik和ReactiveUI进行绑定的问题

问题描述 投票:-1回答:1

我理解这个问题对于telerik控制产品是否过于具体,但是我们将不胜感激。

我在数据表中绑定到telerik组合框时遇到了一些问题。

我将组合框的项目源设置为从数据库中提取的集合。我希望使用所选下拉值中的JobID更新EditableModel。

我要求将组合框的Selected Item设置为存储在JobID属性中的匹配Id。

我玩过这个游戏,但似乎无法正确绑定值。

查看模型

public class EditableViewModel : ReactiveObject
{
    public EditableModel SelectedEntity { get; set; }
    public List<JobModel> Jobs { get; set; }
}

楷模

public class EditableModel
{

    public string Name { get; set; }
    public int JobId { get; set; }
}

public class JobModel
{
    public string Name { get; set; }
    public int Id { get; set; }
}

视图

<reactiveui:ReactiveWindow 
    x:Class="TestWpfApplication.MainWindow"
    x:TypeArguments="test:EditableViewModel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:test="clr-namespace:TestWpfApplication.ViewModels"
    xmlns:reactiveui="http://reactiveui.net"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    Title="NuGet Browser" Height="450" Width="800"
    mc:Ignorable="d">
    <Grid>
        <Grid.Resources>
            <DataTemplate x:Key="MyTemplate">
                <StackPanel>
                    <telerik:DataFormDataField  Label="First Name" DataMemberBinding="{Binding Path=Name, Mode=TwoWay}"  />
                    <telerik:DataFormComboBoxField  Label="Job" SelectedValuePath="Id" DisplayMemberPath="Name" DataMemberBinding="{Binding JobId, Mode=TwoWay}" ItemsSource="{Binding Jobs, Mode=TwoWay}"/>
                </StackPanel>
            </DataTemplate>
        </Grid.Resources>
        <telerik:RadDataForm AutoGenerateFields="False" x:Name="RadDataForm" EditTemplate="{StaticResource MyTemplate}"/>
    </Grid>
</reactiveui:ReactiveWindow>

c# wpf telerik reactiveui
1个回答
0
投票

发现了这个问题。我的DataContext绑定未正确设置

© www.soinside.com 2019 - 2024. All rights reserved.