Trying to use converter on DistinctValues

9 posts, 0 answers
  1. Eli
    Eli avatar
    34 posts
    Member since:
    Oct 2011

    Posted 17 Dec 2012 Link to this post

    Hello,

    I styled the FilteringControl on a RadGrid to include a converter on the list of distinct values to filter by.

    I am using this code in the converter,

                var filter = value as FilteringViewModel;
                if (filter != null)
                {
                    foreach (DistinctValueViewModel distinctValue in filter.DistinctValues)
                    {
                        
                    }
                    return filter.DistinctValues;
                }

                return null;

    But when I put a breakpoint on the code it says that DistinctValues.Count = 0 and the loop will not trigger.

    However, after the converter returns it's value, it shows the distinct values correctly.

    I am wondering why I cannot access the distinct list inside the converter because I know it returns the right value.

    Thank you,
  2. Eli
    Eli avatar
    34 posts
    Member since:
    Oct 2011

    Posted 17 Dec 2012 Link to this post

    Also, I am trying to access the column the filters belong to using var column = filter.GetType().GetField("column"); and it is returning null. How can I get access to the column from within the filter?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 18 Dec 2012 Link to this post

    Hi,

     I'm not sure how this is related to RadDataFilter. Can you clarify? 

    Regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Eli
    Eli avatar
    34 posts
    Member since:
    Oct 2011

    Posted 18 Dec 2012 Link to this post

    Doesn't the FilteringControl from the grid inherited from the RadDataFilter?
  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 18 Dec 2012 Link to this post

    Hello,

     Actually no. Both are completely different and independent. 

    Greetings,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Eli
    Eli avatar
    34 posts
    Member since:
    Oct 2011

    Posted 18 Dec 2012 Link to this post

    Okay, how do I solve the problem?
  8. Eli
    Eli avatar
    34 posts
    Member since:
    Oct 2011

    Posted 26 Dec 2012 Link to this post

    Is this still an open question?
  9. Eli
    Eli avatar
    34 posts
    Member since:
    Oct 2011

    Posted 31 Dec 2012 Link to this post

    Hello? anyone here?
  10. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 02 Jan 2013 Link to this post

    Hi,

    Distinct values are loaded and shaped on demand. We are using our own conversion logic in order to shape how the distinct values look in the UI. Here is how we do it:
    <ListBox x:Name="PART_DistinctValuesList"
         ItemsSource="{Binding DistinctValues}"
         telerik:StyleManager.Theme="{StaticResource Theme}"
         ScrollViewer.HorizontalScrollBarVisibility="Auto"
         SelectionMode="Multiple" ItemContainerStyle="{StaticResource DistinctValueListBoxItemStyle}">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel  MaxHeight="242"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <CheckBox IsChecked="{Binding IsActive, Mode=TwoWay}"
                      Content="{Binding ConvertedValue, Converter={StaticResource DistinctValueConverter}}"
                      VerticalContentAlignment="Center"
                      telerik:StyleManager.Theme="{StaticResource Theme}"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

    So if you want to replace our stock converter with your one you can do it directly in the XAML. Alongside with the ConvertedValue property, the DistinctValueViewModel has another property called RawValue. So you can do something like this in XAML and the raw distinct value will be entering your converter:
    <CheckBox IsChecked="{Binding IsActive, Mode=TwoWay}"
     
                      Content="{Binding RawValue, Converter={StaticResource YourConverter}}"
     
                      VerticalContentAlignment="Center"
     
                      telerik:StyleManager.Theme="{StaticResource Theme}"/>

    The result of what your converter returns will be displayed in the UI as the content of the check-box.

    I hope this helps. Also, placing a question in the correct product forum is always a good idea. RadDataFilter is an independent control that has absolutely nothing to do with RadGridView.

    Regards,
    Rossen Hristov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready