标签: binding

Integer 的 BindableProperty 的 Setter 从未从 xaml (Xamarin.forms) 调用

我正在使用 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)

xaml binding xamarin xamarin.forms

1
推荐指数
1
解决办法
1677
查看次数

在 WPF 中使用 ItemsControl 时正确对齐控件

有人可以告诉我在使用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)

c# wpf binding itemscontrol mvvm

1
推荐指数
1
解决办法
1579
查看次数

ExtJS深度数据绑定

我对 extJs 深度数据绑定有疑问。我有一个组件数据绑定到 viewModel 中的对象。我想更改该对象的一个​​属性并更新组件 tpl。Extjs 不是这样工作的,只有当 viewModel 中的整个对象发生更改时,他才会更新组件。我发现在这种情况下这是 deep:true 属性,但我不知道如何使用它。在该代码中放置深层属性的位置。

           {
            xtype: 'component',
            bind: {
                data: '{someObject}'
            }
Run Code Online (Sandbox Code Playgroud)

data-binding binding extjs extjs5

1
推荐指数
1
解决办法
2528
查看次数

无法在 XAML (Xamarin Forms) 中绑定静态属性

我有一个静态类(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)

由于某种原因,它不起作用。我究竟做错了什么?另外,如何在代码隐藏中设置此绑定?

c# forms xaml binding xamarin

1
推荐指数
1
解决办法
3055
查看次数

1
推荐指数
1
解决办法
1534
查看次数

Angular - 如何通过单向绑定在 ngFor 循环中获取输入值

你能给我一种通过单向绑定在 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)

binding oneway ngfor angular

1
推荐指数
1
解决办法
2万
查看次数

将 label.Text 绑定到从 Xamarin 中的异步任务更新的字符串

因此,我在 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)

然后我只是创建一个新线程来运行任务。就这样。问题是没有值更新到我的用户界面。当我尝试为任务外部的字符串赋值时,它工作正常。我确信我在这里遗漏了一些重要的东西,但我真的不知道是什么。

提前致谢

c# binding multithreading task xamarin

1
推荐指数
1
解决办法
986
查看次数

当按钮位于列表框项内时如何绑定命令

我在列表框内有按钮

 <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)

当我单击按钮时,方法不会被触发。我该如何解决这个问题?

wpf binding mvvm

1
推荐指数
1
解决办法
1585
查看次数

Vuejs 嵌套 v-for 和 &lt;tr&gt; 标签问题

当我尝试在 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/

html binding html-table vue.js v-for

1
推荐指数
1
解决办法
1840
查看次数

支持对象为 NULL 时的 WPF 条件绑定

所以我有一个如下所示的 TextBlock,其中我在中间显示一个名称和绑定名称。

<TextBlock>
    <Run Text="Hello"/> <Run Text="{Binding Name}" /><Run Text=","/>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)

有没有什么方法可以在此处设置一个条件,即当“Name”为 null 时,或者如果当前 DataContext 对象为 null 则更好,那么我根本不显示任何内容?

.net c# wpf xaml binding

1
推荐指数
1
解决办法
1185
查看次数