所以我有一个复杂的形式来创建一个实体,我想用它来编辑我也使用新的角形式API.我将表单的结构与从数据库中检索的数据完全相同,因此我想将整个表单的值设置为此处检索的数据,这是我想要做的示例:
this.form = builder.group({
b : [ "", Validators.required ],
c : [ "", Validators.required ],
d : [ "" ],
e : [ [] ],
f : [ "" ]
});
this.form.value({b:"data",c:"data",d:"data",e:["data1","data2"],f:data});
Run Code Online (Sandbox Code Playgroud)
PS:NgModel不能用于新的表单api我也不介意在模板中使用单向数据绑定
<input formControlName="d" value="[data.d]" />
Run Code Online (Sandbox Code Playgroud)
这有效,但在数组的情况下会很痛苦
所以我有一个带有复选框的viewHolder,这是我的viewModel
@Bindable
var itemIsSelected: Boolean = isSelected
set(value) {
if (field != value) {
field = value
notifyPropertyChanged(BR.itemIsSelected) // this doesn't work
notifyChange() // this one works
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的viewHolder类
inner class SpecialityItemViewHolder(val binding: ItemSpecialityFilterBinding): RecyclerView.ViewHolder(binding.root) {
fun bind(specialityItemViewModel: SpecialityItemViewModel) {
binding.viewModel = specialityItemViewModel
binding.executePendingBindings()
this.itemView.setOnClickListener {
binding.viewModel?.let {
it.itemIsSelected = !it.itemIsSelected // this doesn't trigger ui changes
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
XML
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable
name="viewModel"
type="packagename.ItemViewModel" />
</data>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/vertical_margin_small"
android:paddingBottom="@dimen/vertical_margin_small"
xmlns:app="http://schemas.android.com/apk/res-auto" …Run Code Online (Sandbox Code Playgroud) 我有一个包含颜色列表的 ComboBox,我想使用选定的颜色来填充矩形,所以我这样做了:
var alwan = typeof(Colors).GetTypeInfo().DeclaredProperties;
foreach (var item in alwan)
{
x.Add(item);
}
CbForColors.ItemsSource = x;
CbForColors_Copy.ItemsSource = x;
private void CbForColors_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var color = CbForColors.SelectedItem as PropertyInfo;
//var color2 = color.GetMethod;
//var color3 = color2.Invoke(color,null);
Rect_Sample.Fill = (Color)color.GetValue(null);
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
无法将类型“
Windows.UI.Color”隐式转换为“Windows.UI.Xaml.Media.Brush”
注释行我得到argb了颜色,即。#FFA07FF0(类似的东西)。已经实现的东西有什么问题,我如何从中制作颜色argb?我应该把它变成一个字符串,然后把每 2 个字符变成一个 int 并把它们放在一个新的颜色 a,r,g,b 中吗?
我正在为Windows Phone 8制作一个Tic-Tac-Toe游戏,我想让游戏与自己一起作为主菜单的背景
private Button[] bts;
private List<Button> temp = new List<Button>();
private int[,] winningConditions;
private int counter;
private string Board;
public MainPage()
{
InitializeComponent();
bts = new[] { _1, _2, _3, _4, _5, _6, _7, _8, _9 };
winningConditions = new[,] { { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 }, { 0, 3, 6 },
{ 1, 4, 7 }, { 2, 5, 8 }, { 0, 4, 8 }, { 2, …Run Code Online (Sandbox Code Playgroud)