Microsoft MVP성태의 닷넷 이야기
WPF에서 로딩중 이미지를 구현 - Source [링크 복사], [링크+제목 복사],
조회: 15877
글쓴 사람
우코아
홈페이지
첨부 파일
 

안녕하세요.
소스코드를 간략하게 추려서 추가로 질문 드립니다.

원하는 것은 이미지가 로딩중에 GIF 이미지를 띄워서 '로딩중..'으로 표현하는 것입니다.
구글링을 뒤져가며 더듬더듬 따라해본 방법은 BackgroundWorker, UI쓰레드, 비동기(Async/Await)등을 해보았습니다.
많은 가르침 부탁 드립니다!


# MainWindow.xaml.cs

namespace WpfApp1
{
    /// <summary>
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // GIF 이미지를 표현한 Window
            LoadingProcess loadingProcess;
            loadingProcess = new LoadingProcess();
            loadingProcess.Top = this.Top + (this.ActualHeight - loadingProcess.Height) / 2;
            loadingProcess.Left = this.Left + (this.ActualWidth - loadingProcess.Width) / 2;
            loadingProcess.Show();

            //이미지 로딩 호출
            ImageLoading();
        }

        private void ImageLoading()
        {
            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                (ThreadStart)delegate ()
                {
                    int imageWidth = 88;
                    WrapPanel_Images.Children.Clear();
                    DirectoryInfo di = new DirectoryInfo(@"C:\Users\dp\Desktop\TEST");
                    String fileFilters = "*.jpg|*.jpeg|*.png|*.gif|*.tiff|*.bmp";
                    String[] files = fileFilters.Split('|').SelectMany(searchPattern => Directory.GetFiles(@"C:\Users\dp\Desktop\TEST", searchPattern)).ToArray();

                    for (int i = 0; i < files.Length; i++)
                    {
                        BitmapImage bitmapImage = new BitmapImage();
                        bitmapImage.BeginInit();
                        bitmapImage.UriSource = new Uri(@files[i], UriKind.Absolute);
                        bitmapImage.DecodePixelWidth = 10;
                        bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                        bitmapImage.EndInit();

                        Image image = new Image();
                        image.Stretch = Stretch.Uniform;
                        image.Width = imageWidth;
                        image.Source = bitmapImage;


                        Border border = new Border();
                        border.BorderThickness = new Thickness(1);
                        border.BorderBrush = new SolidColorBrush(Color.FromRgb(41, 57, 86));
                        border.Margin = new Thickness(2, 2, 2, 2);
                        border.Width = imageWidth;
                        border.Height = imageWidth;
                        border.Child = image;

                        TextBlock imageName = new TextBlock();
                        imageName.Text = System.IO.Path.GetFileName(files[i]);
                        imageName.VerticalAlignment = VerticalAlignment.Center;
                        imageName.HorizontalAlignment = HorizontalAlignment.Center;
                        imageName.Margin = new Thickness(0, 0, 0, 10);
                        imageName.MaxWidth = imageWidth - 4;

                        DockPanel dockPanel = new DockPanel();
                        DockPanel.SetDock(border, Dock.Top);
                        DockPanel.SetDock(imageName, Dock.Bottom);
                        dockPanel.Children.Add(border);
                        dockPanel.Children.Add(imageName);

                        WrapPanel_Images.Children.Add(dockPanel);
                    }
                }
            );
        }
    }
}




# Main.Window.xaml
<Window x:Class="WpfApp1.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:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <DockPanel>
            <Grid DockPanel.Dock="Top">
                <Button Click="Button_Click" x:Name="button1">
                    Click
                </Button>
            </Grid>
            <Grid DockPanel.Dock="Bottom">
                <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
                    <WrapPanel x:Name="WrapPanel_Images" Orientation="Horizontal"/>
                </ScrollViewer>
            </Grid>
        </DockPanel>
    </Grid>
</Window>











[최초 등록일: ]
[최종 수정일: 1/4/2019]


비밀번호

댓글 작성자
 



2019-01-04 11시06분
소스 코드가 아니라, 프로젝트를 첨부해 주세요. 아래의 글을 참고하시고.

재현 가능한 최소한의 예제 프로젝트란?
; http://www.sysnet.pe.kr/2/0/11452
정성태

... 76  77  78  79  [80]  81  82  83  84  85  86  87  88  89  90  ...
NoWriterDateCnt.TitleFile(s)
493안연준10/25/200614010스마트클라이언트 배포에서 Config 내용이 이해가 안되요
494안연준10/25/200612183    답변글 [답변]: 스마트클라이언트 배포에서 Config 내용이 이해가 안되요 [2]
489안연준10/23/200613345스마트 클라이언트 배포시 문제점
491안연준10/24/200614045    답변글 [답변]: 스마트 클라이언트 배포시 문제점 [2]
492안연준10/24/200613056        답변글 [답변]: [답변]: 스마트 클라이언트 배포시 문제점
488안연준10/23/200612781닷넷 프레임워크 때문에 일어난 어의없는 상황 [2]
484서민균10/20/200612924스마트 클라이언트 인쇄질문 올린 사람입니다.
486정성태10/22/200614195    답변글 [답변]: 스마트 클라이언트 인쇄질문 올린 사람입니다.
483guest10/19/200613242asp.net 에서 Com+ 등록된 dll 의 차이점이 무엇인지요?
485정성태10/22/200613902    답변글 [답변]: asp.net 에서 Com+ 등록된 dll 의 차이점이 무엇인지요?
490deve...10/23/200617102        답변글 [답변]: [답변]: asp.net 에서 Com+ 등록된 dll 의 차이점이 무엇인지요? [1]
478서민균10/17/200615095스마트 클라이언트로 만든 컴포넌트가 인쇄가 안되요.....ㅜㅜ [5]
477sagi...10/15/200614300bho 와 mfc 메시지 전송 관련 질문입니다.
479정성태10/17/200616064    답변글 [답변]: bho 와 mfc 메시지 전송 관련 질문입니다.
480sagi...10/17/200613998        답변글 [답변]: 감사합니다. [1]
481sagi...10/19/200613914            답변글 [답변]: 죄송합니다 .. 한가지 더 여쭤 볼께요
482정성태10/19/200613445                답변글 [답변]: [답변]: 죄송합니다 .. 한가지 더 여쭤 볼께요
496sagi...10/27/200614127                    답변글 [답변]: 감사드립니다.
476문태정10/11/200616483FarPointSpread로 출력 시 시트 암호설정문제 [1]
474임경훈10/9/200617000세션값이 유지가 안되는데요? [1]
470쿠리마9/29/200613299고수님들께 질문 올립니다. (C# COM Server에서 C++ Client에게 string맴버 포함한 구조체 배열 넘기기)파일 다운로드1
473정성태10/5/200615333    답변글 [답변]: 고수님들께 질문 올립니다. (C# COM Server에서 C++ Client에게 string맴버 포함한 구조체 배열 넘기기) [3]파일 다운로드1
469이방은9/29/200612995질문이 있어요.. [2]
466이승기9/25/200612754Attribute를 이용한 COM 구현 시 interface의 상속 [1]
467이승기9/27/200612337    답변글 [답변]: Attribute를 이용한 COM 구현 시 interface의 상속
4659/23/200611869vb.net에서 c에서 보내는 Post메쎄지를 잡아서 처리할수 없을가요? [1]
... 76  77  78  79  [80]  81  82  83  84  85  86  87  88  89  90  ...