WPF 自定義MessageBox 彈窗提示 彈窗載入

badxnui發表於2018-05-16

1. 下載Dll

       https://pan.baidu.com/s/1sKGQ0uHXHkkhXtMvUYPQHA

2.在專案中新增引用

        略

3.在Xaml中引入名稱空間

     xmlns:myControl ="clr-namespace:MyCustomControlLibrary;assembly=MyCustomControlLibrary"

 

4.先看效果

5.使用程式碼

      Xaml

      <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock Text="提示效果" Foreground="Black" FontSize="16" FontWeight="DemiBold" HorizontalAlignment="Center"/>
                <WrapPanel>
                    <myControl:IconButton Content="提示1" x:Name="AlertOne" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="AlertOne_Click"/>
                    <myControl:IconButton Content="提示2" x:Name="AlertTwo" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="AlertTwo_Click"/>
                    <myControl:IconButton Content="提示3" x:Name="AlertThree" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="AlertThree_Click"/>
                </WrapPanel>

                <TextBlock Text="載入效果" Foreground="Black" FontSize="16" FontWeight="DemiBold" HorizontalAlignment="Center"/>
                <WrapPanel>
                    <myControl:IconButton Content="載入1" x:Name="loadOne" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="loadOne_Click"/>
                    <myControl:IconButton Content="載入2" x:Name="loadTwo" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="loadTwo_Click"/>
                    <myControl:IconButton Content="載入3" x:Name="loadThree" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="loadThree_Click"/>
                </WrapPanel>
                <WrapPanel>
                    <myControl:IconButton Content="載入4" x:Name="loadFour" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="loadFour_Click"/>
                    <myControl:IconButton Content="載入5" x:Name="loadfive" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="loadfive_Click"/>
                    <myControl:IconButton Content="載入6" x:Name="loadSix" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="loadSix_Click"/>
                </WrapPanel>
                <WrapPanel>
                    <myControl:IconButton Content="載入7" x:Name="loadSever" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="loadSever_Click"/>
                    <myControl:IconButton Content="載入8" x:Name="loadeight" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="loadeight_Click"/>
                    <myControl:IconButton Content="載入9" x:Name="loadnine" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="loadnine_Click"/>
                </WrapPanel>
                <WrapPanel>
                    <TextBlock Foreground="#787978" FontSize="14" Text="載入動畫很多,可以自由組織 。"  Padding="10,15,0,0"  MouseLeftButtonUp="OnePointLoading_MouseLeftButtonUp"/>
                </WrapPanel>

                <TextBlock Text="自定義MessageBox效果" Foreground="Black" FontSize="16" FontWeight="DemiBold" HorizontalAlignment="Center" Margin="0,10,0,0"/>
                <WrapPanel>
                    <myControl:IconButton Content="效果1" x:Name="MessageboxOne" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="MessageboxOne_Click"/>
                    <myControl:IconButton Content="效果2" x:Name="MessageboxTwo" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="MessageboxTwo_Click"/>
                    <myControl:IconButton Content="效果3" x:Name="MessageboxThree" Margin="5" Padding="2" IsShowIcon="False" Width="50" HorizontalAlignment="Center" Click="MessageboxThree_Click"/>
                </WrapPanel>
                <!--<StackPanel>
                    --><!--<TextBlock Foreground="#787978" FontSize="14" Text="正在檢測新版本..."  Padding="10,15,0,0"  MouseLeftButtonUp="OnePointLoading_MouseLeftButtonUp"/>--><!--          
                </StackPanel>-->
            </StackPanel>      

 

     Cs程式碼中

 

             private void AlertOne_Click(object sender, RoutedEventArgs e)
        {
            MyCustomControlLibrary.MMessageBox.ShowAlert(
               "Success!",
                Orientation.Horizontal,
                null,
                "#3ca9fe",
                false);

            //  MyCustomControlLibrary.MMessageBox.ShowSuccessAlert();
            // MyCustomControlLibrary.MMessageBox.ShowSuccessAlert("Success!");

        }

        private void AlertTwo_Click(object sender, RoutedEventArgs e)
        {
            var point = this.Mborder.PointToScreen(new Point());
            //Mborder 視窗內容區域的邊框
            var size = new Size(this.Mborder.ActualWidth, this.Mborder.ActualHeight);

            MyCustomControlLibrary.MMessageBox.ShowModalAlert(
                "Success!",
                point,
                size,
                Orientation.Vertical,
               String.Empty,
                "#3ca9fe");
            //MyCustomControlLibrary.MMessageBox.ShowSuccessModelAlert(size,point);
            //MyCustomControlLibrary.MMessageBox.ShowSuccessModelAlert(size, point, "Success!");
        }

        private void AlertThree_Click(object sender, RoutedEventArgs e)
        {
            var point = this.Mborder.PointToScreen(new Point());
            //Mborder 視窗內容區域的邊框
            var size = new Size(this.Mborder.ActualWidth, this.Mborder.ActualHeight);

            MyCustomControlLibrary.MMessageBox.ShowModalAlert(
                "Success!",
                point,
                size,
                Orientation.Vertical,
                 null,
                "#ffffffff");
        }

        private void loadOne_Click(object sender, RoutedEventArgs e)
        {
            MyCustomControlLibrary.MMessageBox.ShowLoading(
                MyCustomControlLibrary.MMessageBox.LoadType.Circle,
                "載入中。。。",
                new Point(0, 0),
                new Size(0, 0),
                "&#xe62e;",
                Orientation.Horizontal,
                "#ffffff",
                3);

        }

        private void loadTwo_Click(object sender, RoutedEventArgs e)
        {
            var point = this.Mborder.PointToScreen(new Point());
            //Mborder 視窗內容區域的邊框
            var size = new Size(this.Mborder.ActualWidth, this.Mborder.ActualHeight);
            MyCustomControlLibrary.MMessageBox.ShowLoading(
                MyCustomControlLibrary.MMessageBox.LoadType.Circle,
                String.Empty,
                 point,
                 size,
                "&#xe62e;",
                Orientation.Horizontal,
                "#ffffff",
                3);
        }

        private void loadThree_Click(object sender, RoutedEventArgs e)
        {
            var point = this.Mborder.PointToScreen(new Point());
            //Mborder 視窗內容區域的邊框
            var size = new Size(this.Mborder.ActualWidth, this.Mborder.ActualHeight);
            MyCustomControlLibrary.MMessageBox.ShowLoading(
            MyCustomControlLibrary.MMessageBox.LoadType.Three,
            "Loading...",
             new Point(0, 0),
            new Size(0, 0),
            null,
            Orientation.Vertical,
            "#ffffff",
            3);
        }

        private void loadFour_Click(object sender, RoutedEventArgs e)
        {

            var point = this.Mborder.PointToScreen(new Point());
            //Mborder 視窗內容區域的邊框
            var size = new Size(this.Mborder.ActualWidth, this.Mborder.ActualHeight);
            MyCustomControlLibrary.MMessageBox.ShowLoading(
                MyCustomControlLibrary.MMessageBox.LoadType.Foure,
                "Loading...",
                point,
                size,
                "&#xe752;",
                Orientation.Vertical,
                "#ffffff",
                5);
        }

        private void loadfive_Click(object sender, RoutedEventArgs e)
        {
            var point = this.Mborder.PointToScreen(new Point());
            //Mborder 視窗內容區域的邊框
            var size = new Size(this.Mborder.ActualWidth, this.Mborder.ActualHeight);
            MyCustomControlLibrary.MMessageBox.ShowLoading(
                MyCustomControlLibrary.MMessageBox.LoadType.Two,
                "Loading...",
                point,
                size,
                "&#xe752;",
                Orientation.Vertical,
                "#ffffff",
                3);
        }

        private void loadSix_Click(object sender, RoutedEventArgs e)
        {
            var point = this.Mborder.PointToScreen(new Point());
            //Mborder 視窗內容區域的邊框
            var size = new Size(this.Mborder.ActualWidth, this.Mborder.ActualHeight);
            MyCustomControlLibrary.MMessageBox.ShowLoading(
                MyCustomControlLibrary.MMessageBox.LoadType.Firve,
                "Loading...",
                point,
                size,
                "&#xe752;",
                Orientation.Vertical,
                "#ffffff",
                3);
        }

        private void loadSever_Click(object sender, RoutedEventArgs e)
        {
            MyCustomControlLibrary.MMessageBox.ShowLoading(
              MyCustomControlLibrary.MMessageBox.LoadType.One,
              "Loading...",
           new Point(0, 0),
            new Size(0, 0),
             null,
              Orientation.Vertical,
              "#ffffff",
              3);
        }

        private void loadeight_Click(object sender, RoutedEventArgs e)
        {
            var point = this.Mborder.PointToScreen(new Point());
            //Mborder 視窗內容區域的邊框
            var size = new Size(this.Mborder.ActualWidth, this.Mborder.ActualHeight);
            MyCustomControlLibrary.MMessageBox.ShowLoading(
                MyCustomControlLibrary.MMessageBox.LoadType.Grid,
                "Loading...",
                point,
                size,
                "&#xe752;",
                Orientation.Vertical,
                "#ffffff",
                3);
        }

        private void loadnine_Click(object sender, RoutedEventArgs e)
        {
            var point = this.Mborder.PointToScreen(new Point());
            //Mborder 視窗內容區域的邊框
            var size = new Size(this.Mborder.ActualWidth, this.Mborder.ActualHeight);
            MyCustomControlLibrary.MMessageBox.ShowLoading(
                MyCustomControlLibrary.MMessageBox.LoadType.One,
                "Loading...",
                point,
                size,
                "&#xe752;",
                Orientation.Vertical,
                "#ffffff",
                3);
        }

        private void MessageboxOne_Click(object sender, RoutedEventArgs e)
        {
            MyCustomControlLibrary.MMessageBox.Reault reault = MyCustomControlLibrary.MMessageBox.ShouBox(
                "操作成功!",
                "資訊",
                MyCustomControlLibrary.MMessageBox.ButtonType.No,
                MyCustomControlLibrary.MMessageBox.IconType.success
                );

            if (reault == MyCustomControlLibrary.MMessageBox.Reault.No)
            {
                MyCustomControlLibrary.MMessageBox.ShowSuccessAlert("你點了 取消");
            }
        }

        private void MessageboxTwo_Click(object sender, RoutedEventArgs e)
        {
            MyCustomControlLibrary.MMessageBox.Reault reault = MyCustomControlLibrary.MMessageBox.ShouBox(
             "操作成功!",
             "資訊",
             MyCustomControlLibrary.MMessageBox.ButtonType.Yes,
             MyCustomControlLibrary.MMessageBox.IconType.success
             );
            var point = this.Mborder.PointToScreen(new Point());
            //Mborder 視窗內容區域的邊框
            var size = new Size(this.Mborder.ActualWidth, this.Mborder.ActualHeight);
            if (reault == MyCustomControlLibrary.MMessageBox.Reault.Yes)
            {
                MyCustomControlLibrary.MMessageBox.ShowSuccessModelAlert(size, point, "你點了 確定");
            }
        }

        private void MessageboxThree_Click(object sender, RoutedEventArgs e)
        {
            MyCustomControlLibrary.MMessageBox.Reault reault = MyCustomControlLibrary.MMessageBox.ShouBox(
           "是否要刪除!",
           "警 告",
           MyCustomControlLibrary.MMessageBox.ButtonType.YesNo,
           MyCustomControlLibrary.MMessageBox.IconType.warring,
           Orientation.Horizontal,
           "是",
           "否"
           );

            if (reault == MyCustomControlLibrary.MMessageBox.Reault.Yes)
            {
                MyCustomControlLibrary.MMessageBox.ShowSuccessAlert("你點了 是");
            }
            else
            {
                MyCustomControlLibrary.MMessageBox.ShowSuccessAlert("你點了 否");
            }
        }

 

相關文章