Telerik Forums
UI for WPF Forum
1 answer
34 views
If I bind the SelectedItem of my TimeLine control to a property of my MainView model, the setter does not run when an item is selected. However, the SelectionChanged event is executed.
Stenly
Telerik team
 answered on 11 Mar 2025
2 answers
53 views

Hello everyone!

I want to let my users display a Speed field: this will be a custom field, of course Speed = Distance / Time.

The problem I have is that some of my records are incomplete (have only either distance or time populated), but those records are still being used.

From what I understand, when I get an aggregate value the aggregation function is always set to sum, and incomplete records are still being put into the sum function (even if the other value is null).

 

I would like to be able to do both of these:

  1. Specify I want to use the AVERAGE function instead of sum.
  2. Exclude incomplete records from the calculation of my calculated field.

 

Thanks for your input!


public class CalculatedSpeedCalculatedField : CalculatedField
{
    private RequiredField distance;
    private RequiredField time;

    public CalculatedSpeedCalculatedField()
    {
        this.Name = "CustomCalculatedSpeed";
        this.DisplayName = "Custom Calculated Speed";
        this.distance = RequiredField.ForProperty("distance");
        this.time = RequiredField.ForProperty("time");
    }

    protected override IEnumerable<RequiredField> RequiredFields()
    {
        return new List<RequiredField>
        {
            this.distance,
            this.time,
        };
    }

    protected override AggregateValue CalculateValue(IAggregateValues aggregateValues)
    {
        var aggregateDistance = aggregateValues.GetAggregateValue(this.distance);
        var aggregateTime = aggregateValues.GetAggregateValue(this.time);

        if (aggregateDistance.IsError())
        {
            return aggregateDistance;
        }
        else if (aggregateTime.IsError())
        {
            return aggregateTime;
        }

        double dist = aggregateDistance.ConvertOrDefault<double>();
        double tim = aggregateTime.ConvertOrDefault<double>();
        return new DoubleAggregateValue(dist / tim);
    }
}

Oscar
Top achievements
Rank 1
Iron
 answered on 11 Mar 2025
1 answer
53 views

Hi,

I have a radgridview which I have configured to sort using "telerik.RadGridView.SortDescriptors" based on whether a checkbox is tick or untick. However, upon ticking/unticking the checkbox, the radgridview does not sort based on the condition that I have specified. May I ask for the solution for this?

Martin Ivanov
Telerik team
 answered on 11 Mar 2025
1 answer
34 views
Hello, how can I bind the color of the individual slices to my viewmodel?
Martin Ivanov
Telerik team
 answered on 10 Mar 2025
1 answer
38 views
As the header state, after downloading the trial version of "Telerik_UI_for_WPF_Documentation_2025_1_211.chm", i opened the chm and navigated to the Contents Tab and when i clicked a topic nothing appears on the right side, What is wrong?
Martin Ivanov
Telerik team
 answered on 06 Mar 2025
1 answer
41 views

I have a record Pitch (see below)

    [TypeConverter(typeof(PitchTypeConverter))]
    public sealed record Pitch(double MinValue, double MaxValue) : IParsable<Pitch>
    {
        public static readonly Pitch Empty = new(0, 0);

        public static Pitch Parse(string s, IFormatProvider provider) 
            => throw new NotImplementedException();
        public static bool TryParse([NotNullWhen(true)] string s, IFormatProvider provider, [MaybeNullWhen(false)] out Pitch result) 
            => throw new NotImplementedException();

        public override string ToString()
            => $"{MinValue}-{MaxValue}";
    }

As you can see , I also have a TypeConverter (currently not fully implemented, but to show the problem it is sufficient).

  public sealed class PitchTypeConverter : TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) 
            => base.CanConvertFrom(context, sourceType);

        public override bool CanConvertTo(ITypeDescriptorContext context, [NotNullWhen(true)] Type destinationType)
            => destinationType == typeof(string);

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) 
            => base.ConvertFrom(context, culture, value);

        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
            => value?.ToString() ?? Pitch.Empty.ToString();

        public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) 
            => base.CreateInstance(context, propertyValues);

        public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) 
            => base.GetCreateInstanceSupported(context);

        public override bool IsValid(ITypeDescriptorContext context, object value) 
            => base.IsValid(context, value);

        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) 
            => base.GetProperties(context, value, attributes);

        public override bool GetPropertiesSupported(ITypeDescriptorContext context) 
            => base.GetPropertiesSupported(context);

        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) 
            => base.GetStandardValues(context);

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) 
            => base.GetStandardValuesExclusive(context);

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context) 
            => base.GetStandardValuesSupported(context);
    }

The Pitch lives inside a ViewModel and is correctly displayed in the RadPropertyGrid, so in that sense everthing works fine.

    [Category("Conditions")]
        [Description("Sets the minimum/maximum allowed pitch limit.")]
        public Pitch PitchLimit
        {
            get => GetProperty(Pitch.Empty);
            set => SetProperty(value);
        }

        [Category("Conditions")]
        public bool RequiresDE
        {
            get => GetProperty<bool>();
            set => SetProperty(value);
        }

 

when I now edit values in the RadPropertyGrid, the RequiresDE works when pressing enter or selecting the checkbox. It doesn't work however when I edit the value for the Pitch property. I can see that the SetProperty for RequiresDE is called, but when editing the PitchLimit the SetProperty is not called.

I honestly out of ideas to find out why the RequiresDE is called and the PitchLimit isn't.

 

Any help is appreciated.

Thanks

 

 

 

 

 

 

Martin Ivanov
Telerik team
 answered on 06 Mar 2025
0 answers
27 views

Hi,

We recently upgraded from 2022.3.912 to 2025.1.211 and it appears that VirtualGrid HeaderSizeNeeded is no longer called after we change VirtualGrid ColumnWidth to flush the cache of column widths. Is this a bug or is there some other way we should be forcing a recalculation of the column widths? Thanks in advance.

__Jason

Jason
Top achievements
Rank 1
 asked on 05 Mar 2025
1 answer
32 views
Hi all

I have tried all sorts of ways (BindingProxy, Converters, DP Helpers..) but I can't seem to get it to work.

I have this:

  <telerik:GridViewDataColumn
      Header="Unit Cost"
      DataMemberBinding="{Binding UnitCost}"
      Style="{StaticResource Style.GridViewDataColumn.Currency}"
      Width="120" />

And the style (simplified) is this:

<Style
    x:Key="Style.GridViewDataColumn.Currency"
    TargetType="{x:Type telerik:GridViewDataColumn}">
    <Setter
        Property="DataFormatString"
        Value="N2" />

    <!-- Cell Template (Display Mode) -->
    <Setter
        Property="CellTemplate">
        <Setter.Value>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition
                            Width="Auto" />
                        <ColumnDefinition
                            Width="*" />
                    </Grid.ColumnDefinitions>
                    <TextBlock
                        Text="$"
                        VerticalAlignment="Center"
                        Margin="5,0" />
                    <TextBlock
                        Text="{Binding ??, StringFormat=N2}"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Right"
                        Grid.Column="1" />
                </Grid>
            </DataTemplate>
        </Setter.Value>
    </Setter>

    <!-- Cell Edit Template -->
    <Setter
        Property="CellEditTemplate">
        <Setter.Value>
            <DataTemplate>
                <telerik:RadMaskedCurrencyInput
                    Value="{Binding Path=??, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                    IsTabStop="True" />
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

How can I define the Path generically. If I hard code UnitCost it works, but I need it to be generic, and I can't find a way to do it.

PS: Design breif is that our company wants to display the $ sign on the left and the value aligned right.

Any insight would be welcomed greatly.
Stenly
Telerik team
 answered on 04 Mar 2025
1 answer
45 views

Hello,

in the "Installing License Key" guide it is specified the license key is personal. But in the "Adding the License Key to CI/CD Services" section it is suggested to create an environment variable to store the license key value. Now because the CD/CD platform in my company is located in cloud and it is shared between all the developers I suppose we need to ask to one of our developers to share with everybody else his personal license key in order to set it as an environment variable in cloud. In my opinion this use case reveals a sort of mismatch in the usage of license key as a "personal".  Is there a way to avoid to use a personal license key as a environment variable?

Thanks,

Alcide

 

 

Martin Ivanov
Telerik team
 answered on 03 Mar 2025
3 answers
1.0K+ views

Hi, 

I have some struggle with context menu binding. The problem is that I cant bind Command from  CustomerViewModel  to a RadMenuItem in a Context menu.

Here is my code:

public class CustomerViewModel : ViewModelBase
{
    private ObservableCollection<Customer> _customers;
 
    public ICommand AddCom { get; set; }
    public ICommand DelCom { get; set; }
    public CustomerViewModel()
    {
        AddCom = new DelegateCommand(Add);
        DelCom = new DelegateCommand(Del);
    }
 
    private void Add(object o)
    {
        Customers.Add(new Customer(){Id=Customers.Count,
                Name="Customer "+ Customers.Count.ToString()} );
        OnPropertyChanged(() => this.Customers);
    }
    private void Del(object o)
    {
        Customers.Remove((Customer) o);
        OnPropertyChanged(() => this.Customers);
    }
     
    public ObservableCollection<Customer> Customers
    {
        get => this._customers;
        set
        {
            if (this._customers == value) return;
            this._customers = value;
            this.OnPropertyChanged(() => this.Customers);
        }
    }
}

and XAML

<Window x:Class="CustomListBoxDragDropBehavior.MainWindow"
        xmlns:local="clr-namespace:CustomListBoxDragDropBehavior"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525" >
    <d:Window.DataContext>
        <local:CustomerViewModel/>
    </d:Window.DataContext>
    <Window.Resources>
        <telerik:RadContextMenu x:Key="Menu">
            <telerik:RadMenuItem Header="Add customer" Command="{Binding ??? }" />
            <telerik:RadMenuItem Header="Remove customer" Command="{Binding ???}"
                   CommandParameter=" ??? "/>/>
        </telerik:RadContextMenu>
        <Style x:Key="ListBoxItem" TargetType="telerik:RadListBoxItem">
            <Setter Property="telerik:RadContextMenu.ContextMenu" Value="{StaticResource Menu}"/>
        </Style>
    </Window.Resources>
 
    <Grid >
        <telerik:RadListBox ItemContainerStyle="{StaticResource ListBoxItem}"
                            ItemsSource="{Binding Customers, Mode=TwoWay}"
                            DisplayMemberPath="Name"
                            >
        </telerik:RadListBox>
    </Grid>
</Window>

I tried few combination like 

<telerik:RadMenuItem Header="Item" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=DataContext.AddCom }" />

with no success. Also I need to pass current customer to a DelCom as parameter.

Please advise.

 

fabrizio
Top achievements
Rank 1
Iron
 updated answer on 03 Mar 2025
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?