我想实现以下目标:我想要一个显示可用COM端口的ComboBox.在启动时(并单击"刷新"按钮)我想获得可用的COM端口并将选择设置为最后选择的值(来自应用程序设置).
如果设置(最后一个COM端口)中的值不在值列表(可用COM端口)中,则会发生以下情况:
虽然ComboBox没有显示任何内容(知道新的SelectedItem不在ItemsSource中"足够聪明"),但ViewModel更新为"无效值".我实际上期望Binding具有与ComboBox显示的值相同的值.
用于演示目的的代码:
MainWindow.xaml:
<Window x:Class="DemoComboBinding.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:local="clr-namespace:DemoComboBinding">
<Window.Resources>
<local:DemoViewModel x:Key="vm" />
</Window.Resources>
<StackPanel Orientation="Vertical">
<ComboBox SelectedItem="{Binding Source={StaticResource vm}, Path=Selected}" x:Name="combo"
ItemsSource="{Binding Source={StaticResource vm}, Path=Source}"/>
<Button Click="Button_Click">Set different</Button> <!-- would be refresh button -->
<Label Content="{Binding Source={StaticResource vm}, Path=Selected}"/> <!-- shows the value from the view model -->
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
MainWindow.xaml.cs:
// usings removed
namespace DemoComboBinding
{
public partial class MainWindow : Window
{
//...
private void Button_Click(object sender, RoutedEventArgs e)
{
combo.SelectedItem = "COM4"; …Run Code Online (Sandbox Code Playgroud) 我希望你们的编码都很好。所以...我正在重构正在使用的GWT应用程序的客户端,我想知道一些事情。日复一日地寻找答案,我决定问您您的观点...
标题是相当理解的,但是有我想做的一小段。
我想改变这样的东西
public AnnotatedObject annotated = GWT.create(AnnotatedObject.class);
Run Code Online (Sandbox Code Playgroud)
通过这样的事情
@CreativeAnnotation
public AnnotatedObject;
Run Code Online (Sandbox Code Playgroud)
我不得不说,在我的xxx.gwt.xml中,我做了这样的事情:
<replace-with class="package.AnnotationObject2">
<when-type-is class="package.AnnotationObject" />
</replace-with>
Run Code Online (Sandbox Code Playgroud)
如您所见,我的递减替换类是AnnotationObject2,目前,我在上面的替换类之间添加了一行,并且有:
<replace-with class="package.AnnotationObject1">
<when-type-is class="package.AnnotationObject" />
<when-property-is name="type" value="object1" />
</replace-with>
<replace-with class="package.AnnotationObject2">
<when-type-is class="package.AnnotationObject" />
<when-property-is name="type" value="object2" />
</replace-with>
Run Code Online (Sandbox Code Playgroud)
我不太喜欢使用xxx.html的元数据,因此我想要的结果是:
@CreativeAnnotation(type = "object2")
public AnnotatedObject;
Run Code Online (Sandbox Code Playgroud)
那么,您是否认为GWT可以实现这种事情(我不得不说我使用GWT 2.5,这是由于客户的需求引起的)吗?如果可以,您能帮我吗?
提前致谢。
编辑:我的意思是,我知道GIN ...只是想知道如何从头开始。
在我的WCF中,我有一些服务.其中一个必须对邮件大小有更大的限制,所以我必须创建另一个绑定并更改配置.
但是......我无法在Web.config中看到我的服务的任何配置 - 没有.什么是默认的?那么我可以在哪里更改服务绑定?
我正在开发一个用于货币编辑的自定义文本框.
我已经看到一些准备使用它们,但它们很复杂和/或实际上不可用,迫使你做坏事(比如硬编码应该在控件上使用的名称).
所以我决定自己做,但是我无法使用绑定选项,因为分配给绑定属性的属性必须是小数,但TextBox控件的Text属性接受字符串.
我想的答案可能是覆盖基类(TextBox)中Text属性的访问方法(getter和setter),但是不允许这样做.
我的绑定应该设置为值,它设置TextBox的text属性将其格式化为文本(带有货币符号和所有内容),但将其转换回Get方法上的数值数据类型.
这是我到目前为止所取得的成就:
public class CurrencyTextBox : TextBox
{
private bool IsValidKey(Key key)
{
int k = (int)key;
return ((k >= 34 && k <= 43) //digits 0 to 9
|| (k >= 74 && k <= 83) //numeric keypad 0 to 9
|| (k == 2) //back space
|| (k == 32) //delete
);
}
private void Format()
{
//formatting decimal to currency text here
//Done! no problems here
}
private void FormatBack()
{
//formatting currency …Run Code Online (Sandbox Code Playgroud) 我对JavaFX中的绑定有疑问。假设我有映射1:“ Aaa”,2:“ Bbb”,3:“ Ccc”,依此类推。我想要的是根据此映射绑定(双向)2个属性IntegerProperty和StringProperty。如何做到这一点?
UPD:我将尝试描述我的用例。我有一堂课
class A {
IntegerProperty num;
...
}
Run Code Online (Sandbox Code Playgroud)
但是在用户界面中,我不想显示此数值,而是显示一些有意义的字符串。所以我想添加StringProperty numValue和绑定num和numValue。在表中,我将numValue用作TableColumn的属性。当用户更改值numValue(例如通过组合框)时,我想num自动更新。
我在Grid.Row和Grid.Column中绘制了一个椭圆.Row总是高于Column宽.
我想绘制一个填充网格列宽度的椭圆,以及它的高度使其成为一个完美的圆.
我还想在上面的椭圆的中心画一个数字.基本上以一个以数字为中心的圆圈结束.
我可以在我的Ellipse和包含数字的TextBlock上轻松设置HorizontalAlignment ="Stretch".这照顾了我的宽度.但是,即使Grid.Column宽度发生变化,如何使Ellipse和TextBlock的高度始终与其宽度匹配?
这里有一些XAML来说明这一点.在下面的XAML中,我希望硬编码的'63'基于Grid.Column宽度或椭圆的宽度范围:
<Ellipse Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch" Height="63" Stroke="Black" StrokeThickness="3" VerticalAlignment="Top"/>
<TextBlock Grid.Row="1" Grid.Column="0" Width="63" Height="63" VerticalAlignment="Top" Text="1" TextAlignment="Center" FontSize="42" FontWeight="Bold"/>
Run Code Online (Sandbox Code Playgroud)
感谢你的帮助.我最终使用了Herdo的答案.只需将HorizontalAlignment设置为Stretch,然后将高度绑定到椭圆的实际宽度即可.我对椭圆和文本块做了同样的事情:
<Ellipse HorizontalAlignment="Stretch" Height="{Binding ActualWidth, RelativeSource={RelativeSource Self}}"/>
<TextBlock HorizontalAlignment="Stretch" Height="{Binding ActualWidth, RelativeSource={RelativeSource Self}}"/>
Run Code Online (Sandbox Code Playgroud) 更新:感谢jgoldberger,我已经解决了
<remove-node path="/api/package[@name='com.spotify.sdk.android.authentication']/interface[@name='AuthenticationClient.AuthenticationCompleteListener']" />
Run Code Online (Sandbox Code Playgroud)
我正在尝试为Android Spotify SDK创建一个Java绑定项目。我已经使用Metadata.xml解决了大多数问题,但是我无法解决最后一个问题。
在SDK中,类AuthenticationClient内有一个私有接口AuthenticationCompleteListener。
我尝试使用
<attr path="/api/package[@name='com.spotify.sdk.android.authentication']/class[@name='AuthenticationClient.AuthenticationCompleteListener']" name="visibility">public</attr>
Run Code Online (Sandbox Code Playgroud)
以及各种变化,包括
<attr path="/api/package[@name='com.spotify.sdk.android.authentication']/class[@name='AuthenticationClient']/interface[@name='AuthenticationCompleteListener']" name="visibility">public</attr>
Run Code Online (Sandbox Code Playgroud)
但是,构建时出现以下错误:
错误:AuthenticationCompleteListener在AuthenticationClient中不是公共的;无法从外部程序包访问。
我能做什么?
感谢您对
弗雷德的帮助
我用Xamarin(Android)+ Mvvmcross创建了简单的应用程序.我的ViewModel中有属性Data(类型MyData).
这是我的VievModel
public class MyViewModel:MvxViewModel
{
private MyData _data;
public MyData Data
{
get { return _data; }
set
{
_data = value;
RaisePropertyChanged(() => Data);
}
}
....
}
public class MyData: INotifyPropertyChanged
{
public string Current
{
get { return _current; }
set
{
_current = value;
Debug.WriteLine(_current);
NotifyPropertyChanged("Current");
}
}
private string _current;
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在视图中使用此绑定
xmlns:local="http://schemas.android.com/apk/res-auto"
<TextView …Run Code Online (Sandbox Code Playgroud) 我无法在用户控件的资源部分中定义的绑定中正常工作。稍后,当我将它绑定到datagrid的列时,相同的绑定似乎可以在xaml中使用。在样式声明中时,它只是不显示数据。
我得到的错误是
System.Windows.Data错误:40:BindingExpression路径错误:在“对象”“ CollectionViewGroupInternal”(HashCode = 5477078)上找不到“ ReceivedDate”属性。BindingExpression:Path = ReceivedDate; DataItem ='CollectionViewGroupInternal'(HashCode = 5477078); 目标元素是'TextBlock'(Name =''); 目标属性为“文本”(类型为“字符串”)
下面的绑定ReceivedDate在运行时无法解析。
<UserControl.Resources>
<!-- Grouped Items Header: Show the messages in a group. ex: date received -->
<Style x:Key="GroupedItemsHeaderStyle" TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander x:Name="exp" IsExpanded="True"
Background="LightGray"
Foreground="Black">
<Expander.Header>
<TextBlock Text="{Binding Path=ReceivedDate, Converter={StaticResource DateToSortGroupConverter}}" Foreground="Black"/>
</Expander.Header>
<ItemsPresenter/>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
在此UserControl的隐藏代码中,我按如下所示设置itemsList。
void MailController_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "CurrentMailBoxContent")
{
var currentMailBox = ((App) Application.Current).MailController.CurrentMailBoxContent;
var …Run Code Online (Sandbox Code Playgroud) 我正在学习有关角度的一切.我知道有很多关于角度绑定的SO问题,但我仍在苦苦挣扎.也许有人可以通过这个例子给我一些清晰度.
.controller('myCtrl',['$scope',function($scope){
//define dummy usermanager "class"
var um = function(){
this.username = 'myUsername';
};
//init dummy user class
var _um = new um();
//Bind usermanager to scope
$scope.UserManager = _um;
//After three seconds set new username
setTimeout(function(){
console.log('set');
_um.username = 'newUsername';
},3000);
}]);
Run Code Online (Sandbox Code Playgroud)
使用基本模板
<p>{{ UserManager }}</p>
Run Code Online (Sandbox Code Playgroud)
在此示例中,它将始终显示为{username:myUsername},并且永远不会更改为{username:newUsername}
如何在此示例中正确使用Angulars双向绑定?
编辑: 看来我可以使用$ scope.$ apply(); 但这似乎不是最好的方法.