Problems with Ribboncombobox

Asked

Viewed 32 times

1

Good afternoon, we are developing a text editing tool. In it we are using the menus with the "Ribboncontrolslibrary", and until the moment everything is right. When I decided to use Ribboncombobox I started the problem, based on an example I tried to come up with a solution, but I cannot pass the information created to the UI.

XAML:

<r:RibbonComboBox x:Name="rcbFontFamily" DataContext="{x:Static data:EditorTexto_ViewModel.FontFace}">
    <r:RibbonGallery MaxColumnCount="1">
        <r:RibbonGallery.GalleryItemTemplate>
            <DataTemplate>
                <Grid>
                    <TextBlock Text="{Binding}" FontFamily="{Binding}"/>
                </Grid>
            </DataTemplate>
        </r:RibbonGallery.GalleryItemTemplate>
    </r:RibbonGallery>

Fontface:

public static ControlData FontFace
    {
        get
        {
            lock (_lockObject)
            {
                string Str = "Font Face";

                if (!_dataCollection.ContainsKey(Str))
                {
                    GalleryData<FontFamily> galleryData = new GalleryData<FontFamily>()
                    {
                        SelectedItem = SystemFonts.MessageFontFamily,
                    };

                    GalleryCategoryData<FontFamily> allFontsCategoryData = new GalleryCategoryData<FontFamily>()
                    {
                        Text = "Todas as fontes"
                    };

                    foreach (FontFamily fontFamily in System.Windows.Media.Fonts.SystemFontFamilies)
                    {
                        allFontsCategoryData.GalleryItemDataCollection.Add(fontFamily);

                    }

                    galleryData.CategoryDataCollection.Add(allFontsCategoryData);

                    Action<FontFamily> ChangeFontFace = delegate(FontFamily parameter)
                    {
                        if (AppWindow != null)
                        {
                            AppWindow.ChangeFontFace(parameter);
                        }
                    };

                    Func<FontFamily, bool> CanChangeFontFace = delegate(FontFamily parameter)
                    {
                        if (AppWindow != null)
                        {
                            return AppWindow.CanChangeFontFace(parameter);
                        }

                        return false;
                    };

                    Action<FontFamily> PreviewFontFace = delegate(FontFamily parameter)
                    {
                        if (AppWindow != null)
                        {
                            AppWindow.PreviewFontFace(parameter);
                        }
                    };

                    Action CancelPreviewFontFace = delegate()
                    {
                        if (AppWindow != null)
                        {
                            AppWindow.CancelPreviewFontFace();
                        }
                    };

                    galleryData.Command = new officersoft.editor.MainWindow.PreviewDelegateCommand<FontFamily>(ChangeFontFace, CanChangeFontFace, PreviewFontFace, CancelPreviewFontFace);

                    _dataCollection[Str] = galleryData;
                }

                return _dataCollection[Str];
            }
        }
    }

If you need more information just ask and sorry for any mistakes, I’m new to c#/wpf.

Solution: To set the information it was only necessary to create the following XAML code:

<r:RibbonComboBox 
    x:Name="rcbFontFamily" 
    SelectionBoxWidth="160"
    IsEditable="True">
    <r:RibbonGallery
        Name="_rgFontFamily"
        ScrollViewer.VerticalScrollBarVisibility="Visible"
        Command="{StaticResource FontFamilyHandler}">
        <r:RibbonGalleryCategory
            Name="_rgcFontFamily"
            ItemsSource="{Binding Source={x:Static Fonts.SystemFontFamilies}}"/>
    </r:RibbonGallery>
</r:RibbonComboBox>

If there are any questions, just ask.

  • 1

    and is also new around here. Welcome to Stackoverflow website. You did well to post your code so it could be helped, but you said there was an error, and this error we are not seeing. I could show more clearly this error?

  • I say error, in the sense of lack of knowledge in programming with c# using wpf... What is not happening is the information processed by the Fontface method, being contained in Ribboncombobox.

  • What error occurs? None? you use Visual Studio?

  • None, just not inserted the information in Ribboncombobox, I think something is missing in XAML or code. I have several doubts if this is the way to do it.

  • Where you got that code ready?

  • 1

    I picked up on some discussion on stackoverflow.com, my initial problem was that I had the information filled out in Ribboncombobox, but when I selected it didn’t change Selecteditem. After some research, I found this "solution" and tried to adapt it to my project. And yes, I am using Visual Studio 2013.

Show 1 more comment

1 answer

0


Solution: To set the information it was only necessary to create the following XAML code:

<r:RibbonComboBox 
    x:Name="rcbFontFamily" 
    SelectionBoxWidth="160"
    IsEditable="True">
    <r:RibbonGallery
        Name="_rgFontFamily"
        ScrollViewer.VerticalScrollBarVisibility="Visible"
        Command="{StaticResource FontFamilyHandler}">
        <r:RibbonGalleryCategory
            Name="_rgcFontFamily"
            ItemsSource="{Binding Source={x:Static Fonts.SystemFontFamilies}}"/>
    </r:RibbonGallery>
</r:RibbonComboBox>

If there are any questions, just ask.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.