- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试创建一个用户控件,目的是允许用户在应用程序中定义他们自己的自定义线性渐变。
到目前为止,我有一个用户控件,它使用以下模型来定义梯度停止点的集合:
public class StopSelectorModel : INotifyPropertyChanged {
#region Field Values
private Task _PropertyT;
private ObservableCollection<GradientStop> _Stops;
private GradientStop _SelectedStop;
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Properties
/// <summary>
/// Get or Set Gradient Stop Collection.
/// </summary>
public ObservableCollection<GradientStop> Stops {
get { return this._Stops; }
set {
this._Stops = value;
this._SelectedStop = value.FirstOrDefault( );
this._PropertyT = Task.WhenAll( new Task[ ] {
this.OnPropertyChanged( "Stops" ),
this.OnPropertyChanged( "SelectedStop" )
} );
}
}
/// <summary>
/// Get or Set Selected Gradient Stop.
/// </summary>
public GradientStop SelectedStop {
get { return this._SelectedStop; }
set {
if ( value == null )
return;
if ( !this._Stops.Contains( value ) )
this._Stops.Add( value );
this._SelectedStop = value;
this._PropertyT = this.OnPropertyChanged( "SelectedStop" );
}
}
#endregion
#region Methods
protected async Task OnPropertyChanged( string P ) {
if ( this.PropertyChanged != null )
await this.PropertyChanged.Async( this, new PropertyChangedEventArgs( P ) );
}
#endregion
#region Constructors
/// <summary>
/// Declare instance of StopSelectorModel.
/// </summary>
/// <param name="Base">GradientStopCollection to wrap.</param>
public StopSelectorModel( ObservableCollection<GradientStop> Base ) { this.Stops = Base; }
/// <summary>
/// Declare default instance of StopSelectorModel.
/// </summary>
public StopSelectorModel( ) : this( new ObservableCollection<GradientStop>( new GradientStop[ ] {
new GradientStop( Colors.White, 0.0D ),
new GradientStop( Colors.Black, 1.0D )
} ) ) { }
#endregion
}
我将其用作 ComboBox 的 DataContext(ItemSource = Stops,SelectedItem = SelectedStop,双向绑定(bind),据我所知,这是类似此类的标准操作程序)。
我还有一个控件,它使用以下颜色模型来定义颜色(基本上是 4 个滑动条):
/// <summary>
/// Wrapper for allowing complete databinding of a System.Windows.Media.Color struct.
/// </summary>
public class ColorModel : INotifyPropertyChanged {
private Task _PropertyT;
private Color _Color;
/// <summary>
/// Get or Set Context Color.
/// </summary>
public Color Color {
get { return this._Color; }
set {
this._Color = value;
this._PropertyT = Task.WhenAll( new Task[ ] {
this.OnPropertyChanged( "Color" ),
this.OnPropertyChanged( "ScA" ),
this.OnPropertyChanged( "ScR" ),
this.OnPropertyChanged( "ScG" ),
this.OnPropertyChanged( "ScB" ),
} );
}
}
/// <summary>
/// Get or Set Color ScA value.
/// </summary>
public double ScA {
get { return this._Color.ScA; }
set {
this._Color.ScA = ( float )value;
this._PropertyT = Task.WhenAll( new Task[ ] {
this.OnPropertyChanged( "Color" ),
this.OnPropertyChanged( "ScA" ),
} );
}
}
/// <summary>
/// Get or Set Color ScR value.
/// </summary>
public double ScR {
get { return this._Color.ScR; }
set {
this._Color.ScR = ( float )value;
this._PropertyT = Task.WhenAll( new Task[ ] {
this.OnPropertyChanged( "Color" ),
this.OnPropertyChanged( "ScR" ),
} );
}
}
/// <summary>
/// Get or Set Color ScG value.
/// </summary>
public double ScG {
get { return this._Color.ScG; }
set {
this._Color.ScG = ( float )value;
this._PropertyT = Task.WhenAll( new Task[ ] {
this.OnPropertyChanged( "Color" ),
this.OnPropertyChanged( "ScG" ),
} );
}
}
/// <summary>
/// Get or Set Color ScB value.
/// </summary>
public double ScB {
get { return this._Color.ScB; }
set {
this._Color.ScB = ( float )value;
this._PropertyT = Task.WhenAll( new Task[ ] {
this.OnPropertyChanged( "Color" ),
this.OnPropertyChanged( "ScB" ),
} );
}
}
protected async Task OnPropertyChanged( string P ) {
await this.PropertyChanged?.Async(
this, new PropertyChangedEventArgs( P ) ).DontBlock( );
}
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Define ColorModel with default White Color.
/// </summary>
public ColorModel( ) : this( Colors.White ) { }
/// <summary>
/// Define ColorModel with provided color.
/// </summary>
/// <param name="C">Color to assign to ColorModel.</param>
public ColorModel( Color C ) { this.Color = C; }
}
所以我们是...如何将我的 ComboBox 的 SelectedItem 的 Color 属性与此 ColorModel 联系在一起? (如果/必要时会提供更多详细信息,但时间有点短)。
提前感谢您的帮助...
为清楚起见 - 我想将 SelectedValue ( Color ) 传递给能够编辑该颜色的控件。
因此操作顺序是让 ComboBox 选择一个渐变停止点,然后(这是我需要帮助的地方)负责调整颜色值的控件。
最佳答案
如果我对你的理解是正确的,你希望在选择项目时显示所选的渐变颜色。
我会为它创建自己的 DataTemplate,并将颜色设置为 GradientStop 中运行时构建颜色的绑定(bind)。根据您是否希望所有组合框项目都着色,这可能会有所帮助:Can I use a different Template for the selected item in a WPF ComboBox than for the items in the dropdown part?
编辑
作为对编辑的回应:如果我理解正确的话,你已经得到了 UserControl,DataContext 是某个 UserControlModel,其中一个子节点是 StopSelectorModel,在这种情况下,我会在 SelectedGradientStop 上设置引发事件,并在 UserControlModel 中处理这个事件.
或者,如果不是父子关系,我会使用 Messanger 并在设置 SelectedGradientStop 时发送消息。
事件和消息都必须包含描述应该使用什么颜色的对象。
关于c# - 如何绑定(bind)到 ComboBox 的 Selected Item 中的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37231843/
这里我试图在 FlatList 中显示一个名为“posts”的数组。 render() { console.log(this.props.posts); return (
这是我的代码: {{day(list)}} {{list.weather[0].description}}
我是 Mahout 的新手,并且仍在使用它。 我的问题是,将 Item-Item 和 User-Item 结合起来是否合适? 我的用例是,一个社交网络应用会尝试根据用户历史数据(优先级较高)为当前用户
下午好, 我按数据库搜索以测试特定类测试,当我放置一个新项目时,如果列表包含该项目。 @Test public void insertAndDeleteTask() throws Interrupte
我有一个关于 ionic 框架的问题,我希望有人能帮助我...我有一个带有“ion-item-right”的 ionic 列表。这一切都可以,按钮在右边。现在我需要其他三个居中的图标,这样我就有了:文
我经常遇到类似下面的代码: if ( items != null) { foreach(T item in items) { //... } } 基本上,if 条件确
我最近问了a question about LocalStorage .使用 JSON.parse(localStorage.item) 和 JSON.parse(localStorage['item
我最近问了a question about LocalStorage .使用 JSON.parse(localStorage.item) 和 JSON.parse(localStorage['item
这个问题已经有答案了: Type mismatch: cannot convert from Item to Item (1 个回答) 已关闭 7 年前。 我很困惑。我无法将外部类的实例变量 Node
我目前正在使用 MUI Grid(但我对替代解决方案持开放态度)并且我想要并排放置两个组件:最右边的组件占 400px宽度和左侧组件占据其余部分。 || || || 当页面宽度缩小时: | | ||
我最近问过a question about LocalStorage 。使用 JSON.parse(localStorage.item) 和 JSON.parse(localStorage['item
public class Document extends Model { ... @ManyToMany public Set accessors; ... } 我想选择访问者包含某个用户的所有文档
我正在使用 selenium webdriver 为单页 Web 应用程序开发一个 Java 框架,使用以下模式:PageObject、SlowLoadableComponent(责任链)、PageF
最近在学习C,在网上发现了一个问题。问题是: What is the problem with this function in terms of memory allocation? What is
我有这个代码 ( -1 ? true : false} /> {genre.item.name}
在ASP.Net中使用DataGrid时真的没有快捷方法吗 (e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.A
我正在使用工作流程根据数据和一组要求将大量 pdf 从一个位置复制到其他大坝位置。我正在使用以下代码 Assets damAsset = manager.createAsset(path, is, m
我是 PowerShell 的新手。 我正在尝试自动将 dll 组件从源服务器上的文件夹部署到目标服务器上的多个文件夹。这看起来应该很简单:将组件从源服务器上的源(部署)文件夹复制到目标服务器上的文件
我的代码: for column_name, column_data in summary_words.iteritems(): if column_name != "summary" and
我的代码: for column_name, column_data in summary_words.iteritems(): if column_name != "summary" and
我是一名优秀的程序员,十分优秀!