In BulletDecorator.Bullet example, bullet is not displayed when app is run

Nicholas Piazza 541 Reputation points
2023-02-22T16:30:20.2133333+00:00

I am trying to run the BulletDecorator.Bullet property XAML example in Microsoft documentation at URL: https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.primitives.bulletdecorator.bullet?view=windowsdesktop-6.0

See the MainWindow.Xaml code below. I can see the bullet (icon.jpg) in the Designer window, but when I build and run the application, the bullet is not displayed. What is the problem?



Developer technologies | .NET | Other
{count} votes

Accepted answer
  1. Jack J Jun 25,296 Reputation points
    2023-02-23T02:21:15.8733333+00:00

    @Nicholas Piazza, Welcome to Microsoft Q&A, based on my test, I reproduced your problem in the c# code but not in Xaml Code.

    For Xaml code, please check if your path is correct, like the following:

     <Grid x:Name="grid1">
            <BulletDecorator>
                <BulletDecorator.Bullet>
                    <Image Width="10" Source="images/Icon.bmp"/>
                </BulletDecorator.Bullet>
                <TextBlock Margin="20,0,0,0">My Expander</TextBlock>
            </BulletDecorator>
    
        </Grid>
    
    

    Path:

    User's image

    In c# code, we need to add BitmapImage.BeginInit() method and BitmapImage.EndInit() method to the current code.

    Like the following:

         public MainWindow()
            {
    
               
                InitializeComponent();
                BulletDecorator bp = new BulletDecorator();
                Image i = new Image();
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = new Uri(@"pack://application:,,/images/Icon.bmp");
                bi.EndInit();
                i.Source = bi;
                i.Width = 10;
                bp.Bullet = i;
                TextBlock tb = new TextBlock();
                tb.Text = "My Expander";
                tb.Margin = new Thickness(20, 0, 0, 0);
                bp.Child = tb;
                //Create the image element.
                Image simpleImage = new Image();
                simpleImage.Width = 200;
                simpleImage.Margin = new Thickness(5);
    
                grid1.Children.Add(bp);
            }
    
    

    My tested result:

    User's image

    For the c# code problem, I recommend that you could give the feedback in the Microsoft Learning page:

    User's image

    Update:

    The Bullet could not work in .NET 5,6 or 7 wpf app, because Microsoft stated that it is currently only supported in .NET Framework version.

    User's image

    But we also could request a feature about it in DC.

    Hope my explanation could help you.

    Best Regards,

    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.