Home Forums WPF controls Xceed Toolkit Plus for WPF How to center the text (Content) of a MaterialToast control

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • rebeldev
    Post count: 7
    #44059 |

    I want to programmatically pop up a MaterialToast control with the text centered in the control. I believe I need to use either Content or ContentTemplate (or both) to accomplish this. How do I do this?

    When I use this code, I see no text in the toast control.

    public string MessageText { get; set; }
    private void PopupToast(string message)
        var materialToast = new MaterialToast();
        materialToast.Owner = listViewGrid;
        materialToast.Location = MaterialToastLocationEnum.Top;
        materialToast.Height = 200D;
        materialToast.Width = 200D;
        materialToast.MaterialAccent = Xceed.Wpf.Toolkit.MaterialControls.MaterialAccentEnum.Green;
        DataTemplate dataTemplate = new DataTemplate();
        FrameworkElementFactory factory = new FrameworkElementFactory(typeof(TextBlock));
        MessageText = message;
        factory.SetBinding(TextBlock.TextProperty, new Binding(MessageText));
        factory.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
        dataTemplate.VisualTree = factory;
        dataTemplate.DataType = typeof(TextBlock);
        materialToast.ContentTemplate = dataTemplate;
        materialToast.FontSize = 16D;
        materialToast.DisplayTime = System.TimeSpan.FromMilliseconds(5000);
        materialToast.HideOnClick = true;
        materialToast.CornerRadius = new CornerRadius(2D);
    Fawzi [Xceed]
    Post count: 722


    Your Binding is not correctly set. You need to specify the Source and a string representing the property to bind to. You should use :
    factory.SetBinding( TextBlock.TextProperty, new Binding( “MessageText” ) { Source = this } );
    instead of
    factory.SetBinding(TextBlock.TextProperty, new Binding(MessageText));

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.