버튼 클릭시 progressBar가 100으로 채워지지 않는 현상
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으로 채워지지 않으니 라벨과 버튼이 사라지는 이벤트도 작동하지 않구요. 어떤부분이 잘못 되었는지 몰라서 질문합니다
Answer 1
0
안녕하세요.개발자park입니다.
https://www.inflearn.com/course/lecture?courseSlug=wpf-subtitles&unitId=111428&tab=curriculum
7:52분초부터 소개되는 내용이 없어보입니다.
추가해주시면 되겠습니다.
감사합니다.
19강 15_2) 템블릿에 List가 없는경우는 어떻게 해야되나요?
0
8
1
page와 windows 사용구분
0
103
2
Microsoft 패키지 설치 후 Exception 문제
0
137
2
MSSQL 2022 버전을 다운로드해도 되나요?
0
556
7
3강 이미지삽입에서 오류가나옵니다.
0
344
2
이벤트에 대해서 감사합니다.
0
119
2
StartupUri
0
133
1
RelayCommand에서 CanExecute 리턴값 질문
0
227
1
UserControl 관련
0
262
1
sql 설치문의
0
304
1
PropertyChanged/RelayComman 관련
0
347
1
SQL설치관련
0
369
1
3강 .NET 이미지 삽입 방법도 알려주세요
1
257
1
7강부터 어려워집니다.
0
410
1
프로젝트 생성시 질문
0
367
1
6) Trigger - Property 설정 문의
0
426
1
유저컨트롤 관련 질문
0
828
2
<d:Button /> vs <Button/>
0
554
2
릴레이커맨드 비동기로직이 아니어도 asyncrelaycommand로 icommand 만드나요?
1
530
1
소스코드 제공해주세요
0
434
1
섹션 1. WPF의 3) 대표적인 컨트롤러 사용 강의 건에 대하여...
0
411
1
소스코드
0
360
1
CellTemplate에 새로만들기가 안떠요
0
357
1
궁금해서 여쭤봅니다
0
635
1

