728x90
반응형

mvvmc 를 하면 Command Property 와 Command 실행시 호출될 Mehtod 를 만들어 준다

 

mvvmc.snippet
0.00MB

[사용방법]
mvvmc 를 쓰고 tab 하여 public 변수명 SaveCommand 기입,
tab 하여 private 변수명 saveCommand 기입  tab 하면 완성.
(saveCommand, SaveCommand 는 예시)

[적용방법]
https://kjcoder.tistory.com/1269

 

[C#] Snippets 적용 방법

https://kjcoder.tistory.com/1268 [WPF] Command snippet (자작) mvvmc 를 하면 Command Property 와 Command 실행시 호출될 Mehtod 를 만들어 준다 [사용방법] mvvmc 를 쓰고 tab 하여 public 변수명 SaveComma..

kjun.kr

 

반응형
728x90
반응형
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace WpfApp4
{
    public class Function
    {
        /// <summary>
        /// Grid를 Bitmap이미지로 변환
        /// </summary>
        /// <param name="grid">이미지 변환 할 Grid</param>
        /// <param name="filePath">저장될 png 파일 경로</param>
        /// <returns></returns>
        public static void SaveControlToImage(FrameworkElement grid, string filePath)
        {
            Size size = new Size(grid.ActualWidth, grid.ActualHeight);

            if (!size.IsEmpty)
            {
                RenderTargetBitmap result = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);

                DrawingVisual drawingvisual = new DrawingVisual();
                using (DrawingContext context = drawingvisual.RenderOpen())
                {
                    context.DrawRectangle(new VisualBrush(grid), null, new Rect(new Point(), size));
                    context.Close();
                }

                result.Render(drawingvisual);

                FileStream stream = new FileStream(filePath, FileMode.Create);

                PngBitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(result));

                encoder.Save(stream);

                stream.Close();
            }
        }
    }
}
반응형
728x90
반응형
        #region SaveJPGFile
        /// <summary> 
        /// jpg 파일 저장하기 
        /// <summary>
        /// 비트맵 소스 
        /// 파일 경로 
        public static void SaveJPGFile(BitmapSource bitmapSource, string filePath) 
        {
            JpegBitmapEncoder jpgBitmapEncoder = new JpegBitmapEncoder();
            jpgBitmapEncoder.Frames.Add(BitmapFrame.Create(bitmapSource)); 

            using(FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) 
            {
                jpgBitmapEncoder.Save(fileStream); 
            } 
        } 
        #endregion

 

사용

ImageSource testImage = ..;
SaveJPGFile((BitmapSource)testImage , filePath);

반응형
728x90
반응형
<TextBlock
    Grid.Row="2"
    Grid.Column="2"
    Margin="5"
    Foreground="#61647a">
    <Run Text="{Binding Width, StringFormat=N2}" />
    <Run Text="×" />
    <Run Text="{Binding Height, StringFormat=N2}" />
</TextBlock>
반응형
728x90
반응형
<TextBlock
    FontSize="18"
    FontWeight="Bold"
    Foreground="#FFFF5C69"
    Text="{Binding Count, StringFormat=N0}"
    TextWrapping="Wrap" />

 

반응형
728x90
반응형

new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFF5462")); 

반응형
728x90
반응형
<Image
    Width="30"
    Height="30"
    Source="pack://application:,,,/Kei.Wpf.Common;component/Images/btn_screen_restore.png" />

위처럼 하면 다른 프로젝트의 이미지를 쓸수 있다.

 

반응형
728x90
반응형

프로젝트 구조가 아래와 같은 폴더구조로 사용되 경우

protected override void ConfigureViewModelLocator()
{
    base.ConfigureViewModelLocator();
 
    // TView - TViewModel 과 연계시키기 위함
    ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
    {
        var viewName = viewType.FullName;
        if (viewName == null) return null;
        viewName = viewName.Replace(".Views.", ".ViewModels.");
 
        var viewAssemblyName = viewType.GetTypeInfo().Assembly.FullName;
        var viewModelName = $"{viewName}Model,{viewAssemblyName} ";
 
        return Type.GetType(viewModelName);
    });
}

 

반응형
728x90
반응형
       <Border CornerRadius="10" Grid.ColumnSpan="2" Margin="20,20,20,0" Background="White" Height="90" Width="300">
            <Border.Effect>
                <DropShadowEffect Direction="-10" Opacity="0.195"/>
            </Border.Effect>
            <Grid Height="80">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="48*"/>
                    <ColumnDefinition Width="4*"/>
                    <ColumnDefinition Width="48*"/>
                </Grid.ColumnDefinitions>
                <StackPanel Grid.Column="0">
                    <TextBlock VerticalAlignment="Center" Text="경기" TextWrapping="Wrap" Margin="10" HorizontalAlignment="Center" FontSize="14" FontWeight="Bold"/>
                    <TextBlock VerticalAlignment="Center" Text="09"   TextWrapping="Wrap" Margin="0" HorizontalAlignment="Center" FontSize="25" FontWeight="Bold"/>
                </StackPanel>
                <StackPanel Grid.Column="1">
                    <Border Margin="5,10,5,10" Height="60" HorizontalAlignment="Center" Background="Transparent" BorderThickness="1,0,0,0" BorderBrush="Gray"/>
                </StackPanel>
                <StackPanel Grid.Column="2">
                    <TextBlock VerticalAlignment="Center" Text="전북" TextWrapping="Wrap" Margin="10" HorizontalAlignment="Center" FontSize="14" FontWeight="Bold"/>
                    <TextBlock VerticalAlignment="Center" Text="07"   TextWrapping="Wrap" Margin="0" HorizontalAlignment="Center" FontSize="25" FontWeight="Bold"/>
                </StackPanel>
            </Grid>
        </Border>

결과

반응형
728x90
반응형

&#x0a; 을 넣으면 개행처리된다.

<TextBlock Text="line1&#x0a;line2"/>

결과
line1
line2

반응형

+ Recent posts