我正在使用 Xamarin.forms 制作应用程序。
我将 BindableProperty 设置为整数。但它的 setter 从未被调用,甚至没有从 xaml 设置。
<... SelectedIndex="{Binding myValue}">
Run Code Online (Sandbox Code Playgroud)
我是不是做错了什么?
谢谢。
public class CircleSegmentControl : StackLayout
{
public static readonly BindableProperty SegmentInitialIndexProperty = BindableProperty.Create("SelectedIndex", typeof(int), typeof(CircleSegmentControl), 0);
public int SelectedIndex {
set{
Debug.WriteLine("setter");
SetValue(SegmentInitialIndexProperty, value);
SelectIndex(value);
}
get{
Debug.WriteLine("getter");
return (int)GetValue(SegmentInitialIndexProperty);
}
}
...
}
Run Code Online (Sandbox Code Playgroud) 有人可以告诉我在使用ItemsControl.
我想在左侧有一个描述,TextBox在右侧有一个在 an 中定义的多个字段的描述,ObservableCollection最终得到如下内容:
First Name: [FirstNameTextBox]
Last Name: [LastNameTextBox]
Date of Birth: [DobTextBox]
Run Code Online (Sandbox Code Playgroud)
但我得到的是这个:
First Name: [FirstNameTextBox]
Last Name: [LastNameTextBox]
Date of Birth: [DobTextBox]
Run Code Online (Sandbox Code Playgroud)
我希望所有文本框都根据最大的<TextBlock>. 如果这是直接在控件中完成的<Grid>,那么这将是直接的,因为所有控件都直接在网格中,并且您只需定义以下列定义
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
Run Code Online (Sandbox Code Playgroud)
I thought I could use the SharedSizeGroup property in the <Grid> but it still doesn't resize correctly. Instead it only displays the <TextBlock> stretch across the <Grid>.
Here's my code:
<Grid Grid.IsSharedSizeScope="True" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="Labels" …Run Code Online (Sandbox Code Playgroud) 我对 extJs 深度数据绑定有疑问。我有一个组件数据绑定到 viewModel 中的对象。我想更改该对象的一个属性并更新组件 tpl。Extjs 不是这样工作的,只有当 viewModel 中的整个对象发生更改时,他才会更新组件。我发现在这种情况下这是 deep:true 属性,但我不知道如何使用它。在该代码中放置深层属性的位置。
{
xtype: 'component',
bind: {
data: '{someObject}'
}
Run Code Online (Sandbox Code Playgroud) 我有一个静态类(Evp),位于Models文件夹中。它有一个Name字符串,带有 getter 和 setter 以及 aPropertyChangedEventHandler及其代码:
public static event PropertyChangedEventHandler StaticPropertyChanged;
private static string _name
public static string Name{
get => _name;
set{
_name = value;
OnStaticPropertyChanged("Name"); } }
private static void OnStaticPropertyChanged(string propertyName)
{
StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(propertyName));
}
Run Code Online (Sandbox Code Playgroud)
在我的 XAML 文件中,这就是我尝试绑定的方式(如果我没记错的话,它在 WPF 4.5 中有效):
<Label Grid.Row="0" Grid.Column="1" TextColor="Beige" Text="{Binding Source={x:Static Models:Evp.Name}}" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" FontSize="30"></Label>
Run Code Online (Sandbox Code Playgroud)
我Models在 XAML 中指定了文件夹ContentPage:
xmlns:Models="clr-namespace:Rdb.Models;assembly=Rdb"
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它不起作用。我究竟做错了什么?另外,如何在代码隐藏中设置此绑定?
如何编写将更改构造函数参数类型的绑定转换?
你能给我一种通过单向绑定在 ngFor 循环中获取输入值的方法吗?
<div *ngFor="let d of dataList">
<input #inputValue type="text" [ngValue]="d.value">
<button *ngIf="!d.open" (click)="d.open = true">change</button>
<button *ngIf="d.open" (click)="save(d.id, NEWVALUE); d.open = false;">save</button>
<button *ngIf="d.open" (click)="d.open = false">cancel</button>
</div>`
Run Code Online (Sandbox Code Playgroud)
如何设置 NEWVALUE?双向绑定很容易。但点击取消后,值已经改变,因为我不想要。所以会避免这种方式。
我发现的一种解决方案是使用(ngModelChange)。
<div *ngFor="let d of dataList">
<input #inputValue type="text" [ngValue]="d.value" (ngModelChange)="dataChanged($event)">
<button *ngIf="!d.open" (click)="d.open = true">change</button>
<button *ngIf="d.open" (click)="save(d.id); d.open = false;">save</button>
<button *ngIf="d.open" (click)="d.open = false">cancel</button>
</div>
private newVal;
dataChanged(val) {
this.newVal = val;
}
save(id) {
saveDb(id, this.newVal);
}
Run Code Online (Sandbox Code Playgroud)
正如我猜测的那样,这不是清晰且优化的代码。
据我所知,使用 # 进行模板绑定也不适用于 ngFor。喜欢
<div *ngFor="let …Run Code Online (Sandbox Code Playgroud) 因此,我在 Xamarin 中有一个监视器页面,其中我需要每秒刷新一次值(从 TcpClient 获取的值)。我在 CS 文件中设置了一个公共字符串,并在 Xaml 中进行了一些基本的绑定,如下所示:<Label Text="{Binding myString}"/>
在我后面的代码中,我运行了一个异步任务来刷新myString. 该任务看起来像这样:
protected async Task syncDisplay(){
while(true){
//TcpClient going on, getting some values
myString = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我只是创建一个新线程来运行任务。就这样。问题是没有值更新到我的用户界面。当我尝试为任务外部的字符串赋值时,它工作正常。我确信我在这里遗漏了一些重要的东西,但我真的不知道是什么。
提前致谢
我在列表框内有按钮
<ListBox HorizontalContentAlignment="Stretch" SelectedItem="{Binding SelectedUser}" ItemsSource="{Binding Users}" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<Button Command="{Binding Remove}" />
<Button Command="{Binding Change}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
在视图模型中
public Command Remove{ get { return new Command(true, new System.Action(RemoveCmd)); } }
public Command Change{ get { return new Command(true, new System.Action(ChangeCmd)); } }
Run Code Online (Sandbox Code Playgroud)
当我单击按钮时,方法不会被触发。我该如何解决这个问题?
当我尝试在 a 中嵌套 a 并在每个 a 上绑定 v-for 时,vue 抱怨属性未定义。有什么问题?
<table>
<thead></thead>
<tbody>
<tr v-for="item in items">
<td>{{ item.name }}</td>
<tr v-for="child in item.children">
<td>{{ child.name }}</td>
</tr>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
这是一个js小提琴: https: //jsfiddle.net/78s3qnz5/
所以我有一个如下所示的 TextBlock,其中我在中间显示一个名称和绑定名称。
<TextBlock>
<Run Text="Hello"/> <Run Text="{Binding Name}" /><Run Text=","/>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)
有没有什么方法可以在此处设置一个条件,即当“Name”为 null 时,或者如果当前 DataContext 对象为 null 则更好,那么我根本不显示任何内容?