我有这样的事情:
<dom-module id="bar-foo">
<template>
<span class$="{{getState()}}">Bar Foo</span>
</template>
<script>
(function() {
class BarFoo {
beforeRegister() {
this.is = 'bar-foo';
this.properties = {
data: {
type: Object,
notify: true,
observer: '_updateData'
};
}
getState() {
if (this.data) {
return this.data.val > 0 ? 'positive' : 'negative';
}
}
}
Polymer(BarFoo);
})();
</script>
</dom-module>
Run Code Online (Sandbox Code Playgroud)
现在,该getState函数仅被调用一次,但该data属性每秒更新一次。更改时是否可以更新 class$ 属性data?
成分:
export class AccountComponent implements OnInit {
public error: any;
currentUser = {};
constructor(private afService: AF) {
afService.getCurrentUserInfo().then(currentUserDetails => {
this.currentUser = currentUserDetails;
});
}
updateUserEntry(fname, lname, phone, bio) {
this.afService.getCurrentUserInfo().then((user) => {
let details = [];
details.push(user);
console.log(details[0].userID);
this.afService.updateUserEntry(details[0].userID, fname, lname, phone, bio).then(() => {
console.log("Updated entry");
})
.catch((error) => {
this.error = error;
console.log("error");
});
});
}
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
形式:
<form>
<dl class="form-group">
<dt><label>First Name</label></dt>
<dd><input [(ngModel)]="currentUser.firstName" name="fname" class="form-control" type="text"></dd>
</dl>
<dl class="form-group">
<dt><label>Last Name</label></dt>
<dd><input …Run Code Online (Sandbox Code Playgroud) 我有一个包含不同数据类型字段的对象:
public class MyObject{
private String field1;
private CustomObject field2;
private int field3;
...
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个MyObject具有多个MyObject节点的树视图,每个节点都有字段(field1、field2、field3..etc )作为子节点。
我知道我可以制作一个字符串的 TreeView 并使用 addNode(MyObject obj) 方法自行填充它,在该方法中我将添加我需要的各个 TreeItems。但是,我使用 TableView 执行此操作,其中我能够将列与字段属性绑定。例如:
TableView<MyObject> table;
TableColumn<MyObject, String> myColumn;
myColumn.setCellValueFactory(new PropertyValueFactory<>("field1"));
Run Code Online (Sandbox Code Playgroud)
有什么办法可以为 a 做类似的事情吗TreeView<MyObject>?我不反对创建一个扩展的子类TreeItem<?>
我正在寻找的最终结果将是这样的:
--> First My Object
->field1: "Value at Field 1"
->field2: "Value at Field 2"
->field3: 3
--> Second My Object
->field1: "Value at Field 1"
->field2: "Value at Field 2" …Run Code Online (Sandbox Code Playgroud) 不幸的是我已经经常遇到这个问题了。在我的 Android 项目中,我使用databinding将类绑定到我的 xml 布局,效果很好。基本上我是按以下方式进行的:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="myClass" type="com.somepackagename.myClass" />
</data>
</layout>
Run Code Online (Sandbox Code Playgroud)
在我的(相当大的)项目中,我经常对variable name许多不同的 xml 布局使用相同的布局。
经过大量重构后,由于以下构建错误,我现在无法再构建项目:
e: error: Cannot resolve type 'myClass'
e: error: cannot generate view binders android.databinding.tool.util.LoggedErrorException: failure, see logs for details.
Cannot resolve type 'myClass'
at android.databinding.tool.util.L.printMessage(L.java:134)
at android.databinding.tool.util.L.e(L.java:107)
at android.databinding.tool.expr.Expr.getResolvedType(Expr.java:386)
at android.databinding.tool.expr.ExprModel.lambda$resolveTypes$1(ExprModel.java:618)
...
Run Code Online (Sandbox Code Playgroud)
虽然 errorMessage 对我来说很清楚并告诉我哪个变量名导致了这个问题,但不幸的是它不是很详细并且没有告诉我:
如果您更改了许多 xml 布局,那么很难找到导致问题的原因。
难道没有更好的方法来调试此类错误吗?
我尝试使用数据绑定将 Button.Text 属性绑定到 C# 属性,但如果更改 C# 属性的值,视图不会更新。
以下是一些代码片段:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:viewmodel="clr-namespace:Xamarin_App.ViewModel"
x:Class="Xamarin_Lernen.MainPage">
<ContentPage.BindingContext>
<viewmodel:MainViewModel/>
</ContentPage.BindingContext>
<StackLayout>
<Button Text="{Binding Text}" Command="{Binding Command}"/>
Run Code Online (Sandbox Code Playgroud)
在 XAML 中只是 StackLayout 内的按钮,我设置了 DataContext
查看型号:
private string _Text;
public string Text
{
get => _Text;
set
{
if (_Text == value)
{
return;
}
_Text = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public ICommand Command { get; }
public MainViewModel()
{ …Run Code Online (Sandbox Code Playgroud) 我在WPF应用程序中有ItemsControl,它绑定到一个对象数组.我正在使用ItemTemplate来呈现列表.我想为列表中的每个项目显示项目顺序,例如
客户1名称:xxxxx年龄:9999
客户2姓名:yyyy年龄:8888
任何想法如何做到谢谢
我做什么
创建一个用户控件,其中一个DependencyProperty绑定到一个字符串数组
public static readonly DependencyProperty TaskListProperty =
DependencyProperty.Register("TaskList",
typeof(string[]),
typeof(MainControl),
null);
public string TaskList
{
get { return (string[])GetValue(TaskListProperty); }
set { SetValue(TaskListProperty, value); }
}
Run Code Online (Sandbox Code Playgroud)
我
为此代码收到了什么错误
get { return (string[])GetValue(TaskListProperty); }
Run Code Online (Sandbox Code Playgroud)
错误:无法将类型'string []'隐式转换为'string'
如何
为什么这个错误发生,不要我注册其源类型为字符串数组?怎么解决?
c# data-binding silverlight dependency-properties windows-phone-7
我知道在这里已经多次询问过这种事情,但我仍然没有完全理解ASP中的线程安全性.
C#:Where Util是一个静态类,而List是一个静态List.
Util.theList= new List<Object>();
Util.theList.Add(someObject);
Run Code Online (Sandbox Code Playgroud)
页面加载一次,然后一秒钟后(POSTACK后1秒)填充Util.theList并重新加载页面以与新填充的列表数据绑定:
this.Repeater.DataSource = Util.theList;
this.Repeater.DataBind();
Run Code Online (Sandbox Code Playgroud)
每次填充List时,它都是INSTANTIATED:
Util.theList= new List<Object>();
Run Code Online (Sandbox Code Playgroud)
如果这不是线程安全的,我怎样才能使其线程安全?我不能让列表非静态并且在同一页面上,因为一个单独的问题,如果数据绑定在page_load上,数据每次都会绑定: OnDataBind只在第一次回发时触发
我正在尝试将input类型绑定date到模型.我能够绑定到time字段,但我遇到了date字段问题.HTML:
<div ng-app ng-controller="HistoryCtrl">
<input type="date" nm-model="startDate" />
<input type="time" ng-model="startTime" />
<input type="date" nm-model="endDate" />
<input type="time" ng-model="endTime" />
<button ng-click="updateForm()">Update</button>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的控制器(简化):
function HistoryCtrl($scope) {
$scope.result = {
result: 'success',
start: '2013-11-23 03:00:00',
end: '2013-11-24 16:30:00',
delta: 0.05681799352169
};
$scope.updateForm = function () {
$scope.updateTimespan($scope.result.start, $scope.result.end);
};
$scope.updateTimespan = function (start, end) {
$scope.startDate = start.split(" ")[0];
$scope.startTime = start.split(" ")[1];
$scope.endDate = end.split(" ")[0];
$scope.endTime = end.split(" ")[1];
} …Run Code Online (Sandbox Code Playgroud) 我有一个C#.NET 4.5 WPF应用程序,带有一个公共静态类.在该类中,我有一个公共静态字符串.我想要的非常简单,我想将该静态字符串绑定到WPF Label,因此每当更新该字符串时,WPF Label也会更新.
我怎样才能以最简单,最简单的方式实现这一目标
下面的静态类
public static class GlobalStats
{
private static void updateValues()
{
srGlobalStatics="example";
}
public static string srGlobalStatics = "";
}
Run Code Online (Sandbox Code Playgroud)
我希望我的WPF标签绑定到该特定srGlobalStatics字符串.
这是我的XAML代码:
<Label Name="lblGlobalStats" Content="lblGlobalStats" HorizontalAlignment="Left"
Margin="10,36,0,0" VerticalAlignment="Top"/>
Run Code Online (Sandbox Code Playgroud)
这不可能吗?
我可以在MainWindow.xaml.cs中编写一个函数,但是我不想尽可能地将不必要的代码放在那里.
将Int值绑定到 aTextView会导致Resources$NotFoundException带有消息“字符串资源 ID #0x2a”(其中0x2a是 的值Int)。为什么会发生这种情况,如何解决?
示例代码: * layout/activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable name="data" type="com.example.Thing" />
</data>
<LinearLayout tools:context=".MainActivity">
<TextView android:text="@{data.x}"/>
</LinearLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
东西.kt:
package com.example
data class Thing(
var x:Int = 42
)
Run Code Online (Sandbox Code Playgroud)主活动.kt:
package com.example
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.example.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
var activityMain:ActivityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main)
activityMain.data = Thing()
}
}
Run Code Online (Sandbox Code Playgroud)我有TextBox:
<TextBox DockPanel.Dock="Bottom"
FontFamily="Consolas"
Text="{Binding Path=Output}"
VerticalScrollBarVisibility="Visible"
HorizontalScrollBarVisibility="Auto"
AcceptsReturn="True"
AcceptsTab="True" />
Run Code Online (Sandbox Code Playgroud)
在这个TextBox内部我想发送一些/添加消息:
public string Output { get; set; }
public void WriteToOutput(string message)
{
Output += DateTime.Now.ToString("dd.MM HH:mm:ss") + " " + message + Environment.NewLine;
}
public void LoadExcelFile()
{
WriteToOutput("Start....")
//SOME CODE
WriteToOutput("End....")
}
Run Code Online (Sandbox Code Playgroud)
输出应如下所示:
Start...
End...
Run Code Online (Sandbox Code Playgroud)
但它没有显示在TextBox中的文本.是什么原因?
更新:我的MainViewModel.cs:
[AddINotifyPropertyChangedInterface]
public class MainViewModel
{
....
}
Run Code Online (Sandbox Code Playgroud)
我正在使用 PropertyChanged.Fody
我在静态类中找到了静态属性的通知属性更改示例.但它不会更新TextBlock中的任何更改.这是代码.
第一个绑定在构造函数中使用"test"字符串,但StaticPropertyChanged始终为null.
public static class InteractionData
{
public static List<string> SelectedDirectories { get; set; }
private static string errorMessage { get; set; }
public static string ErrorMessgae
{
get { return errorMessage; }
set
{
errorMessage = value;
NotifyStaticPropertyChanged("errorMessage");
}
}
static InteractionData()
{
SelectedDirectories = new List<string>();
errorMessage = "test";
}
public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
private static void NotifyStaticPropertyChanged(string propertyName)
{
if (StaticPropertyChanged != null)
StaticPropertyChanged(null, new PropertyChangedEventArgs(propertyName));
}
}
Run Code Online (Sandbox Code Playgroud)
在视图中......
xmlns:error ="clr-namespace:CopyBackup.Providers"
<TextBlock …Run Code Online (Sandbox Code Playgroud) data-binding ×13
c# ×6
wpf ×4
android ×2
javascript ×2
angular ×1
angularjs ×1
asp.net ×1
datatemplate ×1
date ×1
itemscontrol ×1
java ×1
javafx ×1
kotlin ×1
output ×1
polymer ×1
silverlight ×1
textbox ×1
treeview ×1