DataGridTextColumn - How to bind IsReadonly?
By : user3047141
Date : March 29 2020, 07:55 AM
hope this fix your issue what you can do is to create an attached property to handle the change of the IsReadOnly property in the DataGridTextColumn. code :
public class Class1
{
public static void SetIsReadOnly(DependencyObject obj, bool isReadOnly)
{
obj.SetValue(IsReadOnlyProperty, isReadOnly);
}
public static bool GetIsReadOnly(DependencyObject obj)
{
return (bool)obj.GetValue(IsReadOnlyProperty);
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsReadOnlyProperty =
DependencyProperty.RegisterAttached("IsReadOnly", typeof(bool), typeof(Class1), new PropertyMetadata(false, Callback));
private static void Callback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((DataGridTextColumn)d).IsReadOnly = (bool)e.NewValue;
}
}
<sdk:DataGridTextColumn local:Class1.IsReadOnly="True" Binding="{Binding Property1}" Header="Property1"/>
<sdk:DataGridTextColumn Binding="{Binding Name}"
local:Class1.IsReadOnly="{Binding DataSource.IsInEditMode, Source={StaticResource DataContextProxy}, Converter={StaticResource xxxConverter}}"
Header="ReadOnly Header" />
|
Bind DataGridTextColumn with calculation in MVVM
By : Velu
Date : March 29 2020, 07:55 AM
like below fixes the issue As I've already suggested, you can create a view model class for the collection item and populate it as it should be. code :
public class VerificationViewModel
{
public int AuthorizationVerificationId { get; set; }
public double Amount { get; set; }
}
loadOp.Completed += (sender, e) =>
{
IEnumerable<AuthorizationVerification> op =
((LoadOperation<AuthorizationVerification>)sender).Entities;
var models = op.GroupBy(item => item.AuthorizationVerificationId)
.Select(g => new VerificationViewModel
{
AuthorizationVerificationId = g.Key,
Amount = g.Sum(gi => gi.Amount)
})
.ToList();
PagedCollectionView view = new PagedCollectionView(models);
// Everything else is the same
}
//Also change the type of the property which is bound to SelectedItem
public VerificationViewModel SelectedCreditNote { get; set; }
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Credit No"
Binding="{Binding Path=AuthorizationVerificationId}" Width="200"/>
<sdk:DataGridTextColumn Header="Amount"
Binding="{Binding Path=Amount}" MinWidth="100" Width="*"/>
</sdk:DataGrid.Columns>
|
How to bind WPF combobox selected item with a Value Converter to a DataGridTextColumn? Both DataGridTextColumn and combo
By : Madhu
Date : March 29 2020, 07:55 AM
I wish did fix the issue. So what's stopping you from using IValueConverter. Declare under Resource section and use it like this: code :
<DataGrid.Resources>
<namespace:MyConverter x:Key="MyConverter"/>
</DataGrid.Resources>
.....
<DataGridTextColumn Header="Right"
Binding="{Binding SelectedColumn, Mode=OneWay,
UpdateSourceTrigger=PropertyChanged,
Converter={StaticResource MyConverter}}"/>
|
Bind DataGridTextColumn to method WPF
By : Balaianu Andrei
Date : March 29 2020, 07:55 AM
may help you . Is it possible to bind a DataGridTextColumn to a method in my xaml.cs? , You need to use IMultiValueConverter as GertHermans mentioned. code :
<DataGridTextColumn Width="70" Header="Costo">
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource ConcatConverter}">
<Binding Path="Costo" />
<Binding Path="SOSMoneda.Descripcion" />
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
public class ConcatConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameters, CultureInfo culture)
{
return values[0].ToString() + " " + values[1].ToString();
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
|
Can't bind DataGridTextColumn property from another thread (WPF)
By : Kaushika
Date : March 29 2020, 07:55 AM
will be helpful for those in need I'm updating DataGrid through binding from different thread (Task). , So I solved it by making converter. I have made new class code :
public sealed class ColorCodeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
...
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
...
}
}
<local:ColorCodeConverter x:Key="ColorCodeConverter" />
<DataGridTextColumn Header="" Width="10">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="{Binding C7, Converter={StaticResource ColorCodeConverter}}" />
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
|