강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của codezero
codezero

câu hỏi đã được viết

WPF (.NET Core, C#, có phụ đề)

6) Kích hoạt

버튼 클릭시 progressBar가 100으로 채워지지 않는 현상

Đã giải quyết

Viết

·

282

0

MainViewModel.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace WpfApp2.ViewModels
{
  
    internal class MainViewModel
    {

        private int progressValue;

        public int ProgressValue
        {
            get { return progressValue; }
            set 
            { 
                progressValue = value;

   
                NotifyPropertyChanged(nameof(ProgressValue));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

       
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

MainWindow.xaml

<Window x:Class="WpfApp2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp2"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <Style x:Key="testStyle">
            <Setter Property="Button.Background">
                <Setter.Value>

                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="Black"/>
                        <GradientStop Color="#FF16CEA8" Offset="1"/>
                        <GradientStop Color="#FF0C735E" Offset="0.563"/>
                        <GradientStop Color="#FF0B6C58" Offset="0.533"/>
                    </LinearGradientBrush>

                </Setter.Value>

            </Setter>
            <Style.Triggers>
                <!--progressBar1의 value가 100이면 동작-->
                <DataTrigger Binding="{Binding ElementName=progressBar1,Path=Value}" Value="100">

                    <Setter Property="Control.Visibility" Value="Hidden"></Setter>

                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <Label Content="제목" Style="{StaticResource testStyle}" Width="100" Height="40" VerticalAlignment="Top"/>
        <Button Content="버튼" Width="200" Height="50" HorizontalAlignment="Left" Style="{StaticResource testStyle}" Click="Button_Click"/>
        <CheckBox x:Name="check1" Content="체크박스" Width="100" Height="40" Margin="23,125,677,269"></CheckBox>
        <ProgressBar x:Name="progressBar1"  Width="200" Height="20" Value="{Binding ProgressValue}"  />

    </Grid>
</Window>

 

MainWindow.cs

using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApp2.ViewModels;

namespace WpfApp2
{
    
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        MainViewModel viewModel;

        public MainWindow()
        {
            InitializeComponent();

            viewModel = new MainViewModel();

       
            viewModel.ProgressValue = 30;
            DataContext = viewModel;

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            viewModel.ProgressValue = 100;
                        
            
        }
    }
}

 

실행을 하면 처음 30은 채워져있는데 버튼을 클릭했을 때 100으로 채워지지 않습니다. 물론 100으로 채워지지 않으니 라벨과 버튼이 사라지는 이벤트도 작동하지 않구요. 어떤부분이 잘못 되었는지 몰라서 질문합니다

C#

Câu trả lời 1

0

vmproductor0202님의 프로필 이미지
vmproductor0202
Người chia sẻ kiến thức

안녕하세요.개발자park입니다.

https://www.inflearn.com/course/lecture?courseSlug=wpf-subtitles&unitId=111428&tab=curriculum

7:52분초부터 소개되는 내용이 없어보입니다.

추가해주시면 되겠습니다.

감사합니다.

codezero님의 프로필 이미지
codezero
Người đặt câu hỏi

해결했습니다 감사합니다!

Hình ảnh hồ sơ của codezero
codezero

câu hỏi đã được viết

Đặt câu hỏi