【发布时间】:2021-04-17 09:11:16
【问题描述】:
对此的任何提示将不胜感激。我已经在我的视图模型中设置了我的选择器选项并将这个选定的选项保存回我的数据库,我已经将 SelectedItem 绑定到对象模型中的字段属性。但是,当设置默认选定索引时,它不起作用。请帮忙!
代码
<Picker Grid.Column="2"
Grid.Row="0"
x:Name="myPicker"
HeightRequest="40"
WidthRequest="50"
FontSize="14"
Margin="0,15,0,110"
ItemsSource="{Binding BindingContext.UserOptions, Source={x:Reference myPage }}"
SelectedItem="{Binding .UnitAmount }"
SelectedIndex="{Binding CurrentSelectedIndex}"/>
代码隐藏
private int currentSelectedIndex = 0;
public int CurrentSelectedIndex
{
get => currentSelectedIndex;
set
{
currentSelectedIndex = value;
OnPropertyChanged(nameof(CurrentSelectedIndex));
}
}
型号
public void setupSelectedItem()
{
this.CurrentSelectedIndex = 0;
}
public int CurrentSelectedIndex { get; private set; } = 0;
`
【问题讨论】:
-
你的模特在哪里?为什么您为 ItemsSource 指定了来源,但没有为其他绑定属性指定来源?
-
嗨,杰森,感谢您的帮助。我有一个 myPage 的视图模型以及一个我保存回 mongoDB 的数据的模型......这很棘手,因为这个选择器有助于列表视图。第一篇:stackoverflow.com/questions/65672124/…
-
您的帖子需要包含足够的信息来充分说明问题。引用其他帖子中包含的代码是不够的
-
好的,您还需要什么信息?
-
"你的模型在哪里?" - 即,发布您的模型的代码