1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<ListView Name="ImageListView" Foreground="{x:Null}">        
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True" >
                        <Setter Property="FontWeight" Value="Bold" />
                        <Setter Property="Background" Value="Transparent" />
                        <Setter Property="Foreground" Value="Black" />
                        <Setter Property="BorderBrush" Value="Coral" />
                        <Setter Property="BorderThickness" Value="2" />
                    </Trigger>
                </Style.Triggers>
                <Style.Resources>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
                </Style.Resources>
            </Style>
        </ListBox.ItemContainerStyle>
</ListView>

XAML 코드

1
2
3
4
5
6
7
<ListView Name="ImageListView" ScrollViewer.CanContentScroll="False">        
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <EventSetter Event="RequestBringIntoView" Handler="ListBoxItemRequestBringIntoView"/>
            </Style>
        </ListBox.ItemContainerStyle>
</ListView>


CS 코드

1
2
3
4
private void ListBoxItemRequestBringIntoView(object sender , RequestBringIntoViewEventArgs e)
{
    e.Handled = true;
}


Ctrl + a 의 경우 해당 component에 KeyDown event로써 발생하게 되어 있다.


다음과 같은 EventHandler를 등록 시키면 사용이 가능하다.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
private void textBox_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Control)
    {
        if (e.KeyCode == Keys.A)
        {
            this.textBoxPlainText.Focus();
            this.textBoxPlainText.SelectAll();
        }
    }
}


다음과 같이 Drag Enter와 DragDrop event를 다루는 메소드를 추가하면 된다.


반드시 AllowDrop속성이 True로 되어있어야 한다.


다음의 예제는 TextBox에 DragEnter와 DragDrop을 추가했을 경우의 코드이다.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
private void textBox_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}
        
private void textBox_DragDrop(object sender, DragEventArgs e)
{
    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
    foreach (string file in files) 
        Console.WriteLine(file);
} 


+ Recent posts