binding

Error when binding WPF combobox ItemsSource to an Array of Strings

最后都变了- 提交于 2019-12-24 06:45:49
问题 I could not set a combobox's ItemsSource to an Array. I have tried setting the DataContext to the class where the Array is found, and then setting the bindings in XAML class Car { public string[] makes; } ... public MainWindow() { Car _Car = new Car(); _Car.makes = new string[] { "Toyota", "Mitsubishi", "Audi", "BMW" }; this.DataContext = _Car; } and then in XAML <ComboBox Name="cars" Grid.Column="0" Grid.Row="0" Margin="5" ItemsSource="{Binding Path=makes}"/> It doesn't seem to do anything.

WPF binding user control with data in C# code

前提是你 提交于 2019-12-24 06:39:03
问题 I've create user control like this: public partial class View { public View() { InitializeComponent(); } public static DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(TeaserView) ); public string Name { get { return (string)GetValue(NameProperty); } set { SetValue(NameProperty, value); } } } XAML: <UserControl x:Class="Controls.View" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006

WPF: What is the right base class for collections used in data binding?

Deadly 提交于 2019-12-24 05:55:04
问题 I am building an object model with strongly typed collection classes (e.g. CustomerCollection ). I want to support full two-way binding on both the collection itself and all of the data models in the collection. For the models it seems like implementing INotifyPropertyChanged is the right way to wire up the models. But what inferface/base class should I use so that WPF knows when my collection's contents change? 回答1: ObservableCollection<T> - designed specifically for WPF binding. 回答2: I

Change binding if value is empty

落爺英雄遲暮 提交于 2019-12-24 05:40:06
问题 I want to change binding if the value is null or empty. I make this exemple to explain : List<test> list = new List<test>(); list.Add(new test { Name1 = "Bill", Name2 = "Jack" }); list.Add(new test { Name1 = "", Name2 = "Adam" }); TestDataGrid.ItemsSource = list; XAML <DataGridTextColumn Header="Name" Binding="{Binding Name1}" /> in this case will show : Bill "" I want if the first name is null or empty will show the Name2 , then Bill Adam in another way I want to do : <DataGridTextColumn

Setting tooltip to equal content

谁都会走 提交于 2019-12-24 05:30:13
问题 I'm trying to set a data grid's cell's tooltip to be equal to the text inside of a TextBlock in that cell. What I have so far is this: <Style x:Key="CellStyle" TargetType="{x:Type DataGridCell}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="DataGridCell"> <Grid> <TextBlock Margin="2" VerticalAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap" > <ContentPresenter Content="{TemplateBinding Property=ContentControl.Content}" /> <TextBlock.ToolTip>

Setting tooltip to equal content

霸气de小男生 提交于 2019-12-24 05:30:09
问题 I'm trying to set a data grid's cell's tooltip to be equal to the text inside of a TextBlock in that cell. What I have so far is this: <Style x:Key="CellStyle" TargetType="{x:Type DataGridCell}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="DataGridCell"> <Grid> <TextBlock Margin="2" VerticalAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap" > <ContentPresenter Content="{TemplateBinding Property=ContentControl.Content}" /> <TextBlock.ToolTip>

How to bind to a nested class wpf

被刻印的时光 ゝ 提交于 2019-12-24 05:15:11
问题 I have a view model called FieldViewModel: public class FieldViewModel: INotifyPropertyChanged { private Field m_field; public Field FieldData { get { return m_field; } set { m_field = value; NotifyPropertyChanged("FieldData"); } } and the Field class: public class Field : INotifyPropertyChanged { public List<string> SqlTypes { get { return Enum.GetNames(typeof(SqlDbType)).ToList(); } } private string m_FieldName = null; public string FieldName { get { return m_FieldName; } set { m_FieldName

How to set BindingContext of multiple pages to the same ViewModel in Xamarin.Forms?

馋奶兔 提交于 2019-12-24 04:56:11
问题 I'm new to Xamarin.Forms and I'd like to create a cross-platform app using MVVM pattern and XAML. In my forms project (pcl) I'd like to set the BindingContext of my MainPage and also multiple pages in the future to the same ViewModel. Is this possible? Let me show what I'm talking about. Below is a code snippet from an earlier WPF project of mine ( App.xaml.cs ): public partial class App : Application { private MainWindow _MainWindow; private MyViewModel _ViewModel; public App() { _ViewModel

MVVM INotifyPropertyChanged conflict with base class PropertyChange

余生颓废 提交于 2019-12-24 04:36:06
问题 I'm relatively new to MVVM and I'm trying to understand how INotifyPropertyChanged interface works and how to implement it in my models. The approach that I decided to take was to implement it in each of my Business Object classes. The problem with that approach is that when I bind my View to a property in a Base class the PropertyChanged event in that base class never gets initialized (is null) and therefore the View does not refresh the data for that element when my Model changes. I was

WPF Binding User Entertainment

亡梦爱人 提交于 2019-12-24 04:23:06
问题 I have ran into a situation where I have an ItemsControl generate a pretty complex visual tree from a data collection, dead simple: <ItemsControl ItemsSource="{Binding Items}"/> The small problem I have is when the initial binding construction occurs it can take a "noticeable" amount of time when it is building itself (anywhere from 1/2 a second to 2 seconds depending on tree complexity). During this period the UI thread is completely unresponsive (animations hang, clicks are unregistered,