Chnagelog not showing up after ClickOnce application is updated

17 Views Asked by At

I'm currently working on implementing a changlog display functionality into my ClickOnce application built (using WPF and .NEt 4.8). The application is working fine, it notifies users whenever there is an update, but I'm having difficulites implementing the chagnelog so users can be promted with a dialog after update has been completed shwoing what has been modified /changed.

I tried using the "UpdateCompleted event and have subscribed to it using UpdateCompletedEventHandler. Within this handler, I'm invoking a method called "ShowChnagelog() from within the Mainwindow so supposedly, it should open the Diaglog.

here is my code so far

App.xaml.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Deployment.Application;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace internaltesting
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // Subscribe to the UpdateCompleted event
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                ApplicationDeployment.CurrentDeployment.UpdateCompleted += UpdateCompletedEventHandler;
            }
        }

        private void UpdateCompletedEventHandler(object sender, AsyncCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    if(Application.Current.MainWindow is  MainWindow mainWindow)
                    {
                        mainWindow.ShowChangelog();
                    }
                });
            }
        }
    }
}

MainWindow.xaml.cs

  public void ShowChangelog()
        {
            
            changelogRichTextBox.Visibility = Visibility.Visible;
            okayButton.Visibility = Visibility.Visible;
        }
        private void UpdatesButton_Click(object sender, RoutedEventArgs e)
        {
           
            var contextMenu = new ContextMenu();
            
            var menuItemLatestUpdates = new MenuItem { Header = "Latest Updates" };
           
            menuItemLatestUpdates.Click += LatestUpdates_Click;
            menuItemLatestUpdates.Cursor = Cursors.Hand;
           
            contextMenu.Items.Add(menuItemLatestUpdates);

            contextMenu.IsOpen = true;
        }

       

        private void LatestUpdates_Click(object sender, RoutedEventArgs e)
        {
            try
            {
              

                
                ShowChangelog();
            }
            catch (Exception ex)
            {
                
                MessageBox.Show("Error reading changelog: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void OkayButton_Click(object sender, RoutedEventArgs e)
        {
           
            changelogRichTextBox.Visibility = Visibility.Collapsed;
            okayButton.Visibility = Visibility.Collapsed;
        }

MainWindow.xaml

<Button Content="Updates" Click="UpdatesButton_Click" Cursor="Hand"  HorizontalAlignment="Left"  VerticalAlignment="Top" Margin="540,0,0,0" Width="100" >
                <Button.ContextMenu>
                    <ContextMenu>
                        
                        <MenuItem Header="Latest Updates" Click="LatestUpdates_Click" Cursor="Hand" />
                    </ContextMenu>
                </Button.ContextMenu>
            </Button>


  <Grid>

            <RichTextBox x:Name="changelogRichTextBox" HorizontalAlignment="Stretch" VerticalAlignment="Center" Width="450" Height="300" Visibility="Collapsed" >
                <FlowDocument>
                    <Paragraph>
                        <!-- Use Inlines to style the content -->
                        <Bold FontSize="20">Changelog</Bold>
                    </Paragraph>
                    <Paragraph>
                        <Bold FontSize="16">Version 1.0.0.4</Bold>
                    </Paragraph>
                    <Paragraph>
                        <Bold>Modifications:</Bold>
                    </Paragraph>
                    <List MarkerStyle="Disc">
                        <ListItem>
                            <Paragraph>Added Initialize button and Force initalize button.</Paragraph>
                        </ListItem>
                        <ListItem>
                            <Paragraph>Show Dialog with changes made on the program.</Paragraph>
                        </ListItem>
                        <ListItem>
                            <Paragraph>Added a few new sale commands.</Paragraph>
                        </ListItem>
                        <ListItem>
                            <Paragraph>Added a feedback Textbox.</Paragraph>
                        </ListItem>
                    </List>
                    <Paragraph>
                        <Bold>Bug Fixes:</Bold>
                    </Paragraph>
                    <List MarkerStyle="Disc">
                        <ListItem>
                            <Paragraph>Fixed the ebtsf and ebtw ref number not auto generating after completing sale.</Paragraph>
                        </ListItem>
                    </List>
                </FlowDocument>
            </RichTextBox>

            <Button x:Name="okayButton" Content="Okay" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,165" Click="OkayButton_Click" Width="50" Background="Silver"  Cursor="Hand" Visibility="Collapsed"/>
        </Grid>
    </Grid>

Pleae help me.

Thanks in advance.

0

There are 0 best solutions below