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

반응형
728x90

Expander 의 Header 를 아래처럼 커스텀 할수 있다.

Download & run this example

<Expander Margin="10">
    <Expander.Header>
<DockPanel VerticalAlignment="Stretch">
    <Image Source="/WpfTutorialSamples;component/Images/bullet_green.png" Height="16" DockPanel.Dock="Left" />
    <TextBlock FontStyle="Italic" Foreground="Green">Click to show/hide content...</TextBlock>
</DockPanel>
    </Expander.Header>
    <TextBlock TextWrapping="Wrap" FontSize="18">
    Here we can have text which can be hidden/shown using the built-in functionality of the Expander control.
    </TextBlock>
</Expander>

 

 

아래는 스크롤 가능한 Expander 예시

<Expander Width="200" HorizontalContentAlignment="Stretch">
   <Expander.Header>
     <BulletDecorator>
       <BulletDecorator.Bullet>
         <Image Width="10" Source="images\icon.jpg"/>
       </BulletDecorator.Bullet>
       <TextBlock Margin="20,0,0,0">My Expander</TextBlock>
     </BulletDecorator>
   </Expander.Header>
   <Expander.Content>
     <ScrollViewer Height="50">
       <TextBlock TextWrapping="Wrap">
         Lorem ipsum dolor sit amet, consectetur adipisicing elit, 
         sed do eiusmod tempor incididunt ut labore et dolore magna 
         aliqua. Ut enim ad minim veniam, quis nostrud exercitation 
         ullamco laboris nisi ut aliquip ex ea commodo consequat. 
         Duis aute irure dolor in reprehenderit in voluptate velit 
         esse cillum dolore eu fugiat nulla pariatur. Excepteur sint 
         occaecat cupidatat non proident, sunt in culpa qui officia 
         deserunt mollit anim id est laborum.
       </TextBlock>
     </ScrollViewer>
   </Expander.Content>
 </Expander>

반응형
728x90
        private void listItemButton_Click(object sender, RoutedEventArgs e)
        {
            // 버튼이 포함된 아이템 선택
            var curItem = ((ListBoxItem)this.listBox.ContainerFromElement((Button)sender)).Content;

            this.listBox.SelectedItem = curItem;
        }

 

반응형
728x90

xaml 코드 상위에 아래 처럼 정의를 먼저하고

xmlns:sys="clr-namespace:System;assembly=mscorlib"

아래처럼 사용합니다.

<TextBlock Text="{Binding Source={x:Static sys:DateTime.Now}, 
   StringFormat='{}{0:yyyy-MM-dd HH:mm:ss}', Mode=OneWay}" />

 

 

반응형
728x90

 

 


testButton.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));

위처럼 CheckBox 이벤트도 처리할수 있다


testCheckBox.RaiseEvent(new RoutedEventArgs(CheckBox.CheckedEvent));
testCheckBox.RaiseEvent(new RoutedEventArgs(CheckBox.UncheckedEvent));

반응형
728x90

IRegionMemberLifetime.KeepAlive 를 view 혹은 viewmodel에 구현하면
RequestNavigate 로 view가 변경될때 마다 Instace를 유지할지 새로 생성할지 설정할 수 있다.

    public class ViewAViewModel : BindableBase, INavigationAware, IRegionMemberLifetime
    {
        public ViewAViewModel()
        {

        }

        public bool KeepAlive
        {
            get
            {
               // false를 return시 현재 인스턴스는 Dispose 된다 .
               // true를 return시 현재 인스턴스는 유지된다 .
                return false;
            }
        }
      }

반응형
728x90

/// <summary>

/// 이미지 사각형을 그림니다

/// </summary>

/// <param name="imageSource">이미지입니다.</param>

/// <param name="rect">사각형입니다.</param>

/// <param name="angle">사각형의 Angle 값입니다</param>

/// <returns>이미지에 Angle 이 적용된 사각형이 그려져 반환됩니다</returns>

public static ImageSource ConvertVisionImageInfoToScanImageSource(ImageSource imageSource, Rect rect, double angle)

{

    System.Windows.Media.Imaging.BitmapSource bImage = imageSource as System.Windows.Media.Imaging.BitmapSource;

 

    DrawingVisual dVisual = new DrawingVisual();

    using (DrawingContext dc = dVisual.RenderOpen())

    {

        dc.DrawImage(bImage, new Rect(0, 0, bImage.PixelWidth, bImage.PixelHeight));

 

        // 원본이미지 중심 기준으로 Angle 을 돌립니다.

        dc.PushTransform(new RotateTransform(angle, bImage.PixelWidth / 2, bImage.PixelHeight / 2));

        dc.DrawRectangle((SolidColorBrush)(new BrushConverter().ConvertFrom(Colors.Blue)), null, rect);

    }

 

    System.Windows.Media.Imaging.RenderTargetBitmap targetBitmap = new System.Windows.Media.Imaging.RenderTargetBitmap(bImage.PixelWidth, bImage.PixelHeight, bImage.DpiX, bImage.DpiY, PixelFormats.Default);

    targetBitmap.Render(dVisual);

 

    System.Windows.Media.Imaging.WriteableBitmap wBitmap = new System.Windows.Media.Imaging.WriteableBitmap(targetBitmap);

 

    return wBitmap;

}

 

반응형

+ Recent posts