我需要为输入创建 keyPress (enter) 绑定。
<div id="body">
<input type="text" data-value-update="keyup" data-bind="value: text, keyPress: onKeyPress"/>
<div id="output"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
js:
kendo.data.binders.widget.keyPress = kendo.data.Binder.extend({
init: function (element, bindings, options) {
kendo.data.Binder.fn.init.call(this, element, bindings, options);
var binding = this.bindings.keyPress;
$(element.input).bind("keypress", function (e) {
if (e.which == 13) {
binding.get();
}
});
},
refresh: function () { }
});
var viewModel = kendo.observable({
text: '',
onKeyPress: function () {
$("#output").append("<div>keyPress</div>");
}
});
kendo.bind("#body", viewModel);
Run Code Online (Sandbox Code Playgroud)
我有错误:
错误:输入元素不支持 keyPress 绑定
jsfiddle 中的示例http://jsfiddle.net/dude_jsfiddle/byA75/
我有一个 ListBox 停靠在窗口的左侧,其宽度应与其内容大小相符。当我滚动列表框时,它的宽度会摆动并变得比应有的更宽。基本上我认为正在发生的是 ListBox 计算它所有子项的大小以确定它自己的大小,但似乎只评估实际在屏幕上的控件的可见性绑定(大概是出于性能原因)。结果是它错误地计算了屏幕外子项的大小,为隐藏控件保留了空间。
如果列表中的项目少于窗口高度(因此没有滚动条),则列表始终具有正确的宽度,并且当您滚动到顶部或底部时,它始终对齐到正确的宽度。只有当滚动条位于两者之间时,宽度才错误。
我整个晚上都在努力解决这个问题,尝试了各种重构,比如使用 DataTemplateSelector 来抽象出对可见性绑定的需求,但我最终得到了我不满意的非常肮脏的解决方法。我想解决手头的实际问题而不是躲避它。任何指针将不胜感激。
在以下示例中,列表的大小似乎与 Foo 和 Bar 的宽度相同。更改 StackPanel 方向会使其大小调整为 Foo 和 Bar 中较长者的宽度。希望这是有道理的。
<ListBox ItemsSource="{Binding Widgets}" DockPanel.Dock="Left">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Visibility="{Binding ShowFoo, Converter={StaticResource BoolToVisConverter}}" Text="{Binding Foo}" />
<TextBlock Visibility="{Binding ShowBar, Converter={StaticResource InverseBoolToVisConverter}}" Text="{Binding Bar}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud) 我在绑定到网格的可见性时遇到了麻烦。我有一些项目,我以前做过这个,并试图复制以前使用的相同编码,我已经搜索并根据其他一些文章在 bool 中添加到可见性转换器,但仍然没有。
到目前为止,我在这个项目中所做的就是提供一组将提供给用户的选项。当他们选择一个选项时,它会显示子选项或将它们带到适当的区域。我将绑定设置为 bool 对象,有时会创建一些小消息框和其他消息框,只是为了让我知道程序是否无处不在。一路上我得到了每个消息框,所以它似乎到达了每一段代码。
任何人都可以阐明我做错了什么或指出我正确的方向吗?
Windows.Resources 中的转换器(编辑以显示 Windows.Resources 中的所有代码)
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="FontSize" Value="15"/>
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Height" Value="50" />
<Setter Property="Width" Value="100" />
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)
窗口其余部分的代码
<Grid>
<Grid x:Name="grid_mainMenu" Visibility="{Binding MainMenuVisibility, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="0,0,0,20">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Button x:Name="button_Items" Content="Items" Grid.Row="0" Click="button_Items_Click"/>
<Button x:Name="button_Orders" Content="Orders" Grid.Row="1" Click="button_Orders_Click" />
<TextBox Text="{Binding StatusMessage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,0,0" HorizontalAlignment="Left" …Run Code Online (Sandbox Code Playgroud) 我正在尝试将进度条绑定到服务的进度。我在场景构建器中创建了进度条,并尝试了以下代码。但是进度条一直在运行,并不代表它所连接的服务。它应该在服务运行时运行,并代表正在下载的数据。如何绑定进度条来表示我创建的服务。
@FXML
private ProgressBar ProgressBar;
service.start();
ProgressBar.progressProperty().bind(service.workDoneProperty());
Run Code Online (Sandbox Code Playgroud) 我知道这个问题已经被问过和回答过好几次了,但我仍然不明白。我好像少了一点理解。
我有一个 TabControl 绑定到一个可观察的视图模型列表。当然,视图模型可以是不同的类型,从相同的基本类型派生而来。当一个视图模型被添加到列表中时,我希望 tabcontrol 根据视图模型的类型添加一个新的 tabpage。
我不明白如何设置 TabControl 的 ContentTemplate 以根据视图模型的类型选择正确的视图。
可以在此处找到一个基本示例,但我没有使用动态视图启动和运行它:
如何将 TabControl 的项绑定到 wpf 中的可观察集合?
谢谢!约翰内斯
我知道它已经在这里出现了一百万次,但我不知道我的代码有什么问题。我尝试了一切,但ComboBox没有SelectedItem正确绑定。这是我完整的沙箱解决方案。您也可以在 GitHub ( https://github.com/LukasNespor/ComboBoxBinding )上找到它。
BindableBase.cs
public class BindableBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public virtual void RaisePropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Run Code Online (Sandbox Code Playgroud)
ContactModel.cs
public class ContactModel : BindableBase
{
private int _Id;
public int Id
{
get { return _Id; }
set
{
_Id = value;
RaisePropertyChanged(nameof(Id));
}
}
private string _Name;
public string Name
{
get { return _Name; }
set
{
_Name = value;
RaisePropertyChanged(nameof(Name));
}
} …Run Code Online (Sandbox Code Playgroud) 我面临以下错误“响应消息的内容类型 text/html 与绑定的内容类型不匹配 (application/soap+xml; charset=utf-8)。如果使用自定义编码器,请确保IsContentTypeSupported 方法已正确实现。响应的前 514 个字节为"。下面是我的绑定和配置文件
<customBinding>
<binding name="LoginServiceSoap12Binding">
<textMessageEncoding messageVersion="Soap12" />
<httpsTransport />
</binding>
</customBinding>
<endpoint address="WCF URL"
binding="customBinding" bindingConfiguration="LoginServiceSoap12Binding"
contract="CWALoginService.LoginServicePortType" name="LoginServiceHttpsSoap12Endpoint" />
Run Code Online (Sandbox Code Playgroud)
不确定我在这里面对的是什么问题...
我需要将标签绑定到一个复合值 - 由模型中的几个值组成。我正在尝试使用 ValueConverter 来执行此操作,但我无法弄清楚如何将对象本身传递给 ValueConverter。这是我的代码:在 XAML 中:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MyApp;assembly=MyApp"
x:Class="MyApp.SavedDetailsPage">
<ContentPage.Resources>
<ResourceDictionary>
<local:DetailsConverter x:Key="detailsCvt" />
</ResourceDictionary>
</ContentPage.Resources>
...
<Label Text="{Binding ???, Converter={StaticResource detailsCvt}}" FontSize="Small" TextColor="Gray" />
...
Run Code Online (Sandbox Code Playgroud)
在 DetailsConverter.cs 中:
class DetailsConverter : IValueConverter
{
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
MyModel myModel = (MyModel)value;
return (myModel.FirstName + " " + myModel.LastName);
}
...
Run Code Online (Sandbox Code Playgroud)
我尝试使用“。” 用于绑定到 self ,但这不起作用。
我通过向 MyModel 添加一个 .This 属性找到了一种解决方法,它可以访问对象本身,因此我可以在 XAML 绑定中传递“This”,但不确定这是否是最好的方法。
提前致谢!
我必须使用 Typescript 使用 AngularJs 1.5.8 进行以下设置:
我有一个包含目录(项目的二维数组)的父组件。从我将目录中的每个列表传递给子组件的位置:
...
export class ParentController {
private catalog = []; //contains a list of lists
...
private printCallback(item: any): void {
console.log(item);
}
}
Run Code Online (Sandbox Code Playgroud)
和模板:
<div ng-repeat="list in $ctrl.catalog">
<child content="list" callback="$ctrl.printCallback(item)"></child>
</div>
Run Code Online (Sandbox Code Playgroud)
现在在子组件中,我再次遍历列表中的每个项目。每当我单击列表中的项目时,我都希望父项知道我单击的项目:
export class ChildComponent implements IComponentOptions {
template: any = require('./child.component.html');
public bindings: any = {
content: '<',
callback: '&'
};
controller: any = ChildController;
}
export class ChildController {
public content: Array<any>;
public callback;
...
public onTrigger(item: any): void { …Run Code Online (Sandbox Code Playgroud) 我决定通过按页面上的键来复制按钮,但收到如下错误:
“1”不能用作“Key”的值。数字不是有效的枚举值。
<Page.InputBindings>
<KeyBinding Command="{Binding Btn_Click}"
CommandParameter="{Binding ElementName=btn1,Path=Content}"
Key="1"/>
<KeyBinding Command="{Binding Btn_Click}"
CommandParameter="{Binding ElementName=btn2,Path=Content}"
Key="2"/>
<KeyBinding Command="{Binding Btn_Click}"
CommandParameter="{Binding ElementName=btn3,Path=Content}"
Key="3"/>
<KeyBinding Command="{Binding Btn_Click}"
CommandParameter="{Binding ElementName=btn4,Path=Content}"
Key="4"/>
</Page.InputBindings>
Run Code Online (Sandbox Code Playgroud)
我可以欺骗系统吗?
binding ×10
c# ×5
wpf ×5
javascript ×2
xaml ×2
angularjs ×1
combobox ×1
javafx ×1
kendo-ui ×1
keyboard ×1
mvvm ×1
observable ×1
progress-bar ×1
service ×1
tabcontrol ×1
typescript ×1
utf-8 ×1
visibility ×1
wcf ×1