0
我創建了自定義列表框並基於布爾我想禁用鼠標懸停和鼠標選擇少數項目。我使用Style類並在自定義列表框的代碼中設置樣式。我的代碼如下:禁用鼠標懸停和選擇自定義列表中的選定項目
public class DragDropListBox : ListBox
{
public DragDropListBox()
{
Style itemContainerStyle = new Style(typeof(ListBoxItem));
itemContainerStyle.Setters.Add(new EventSetter(ListBoxItem.DropEvent, new DragEventHandler(ListBoxItemDropHandler)));
this.ItemContainerStyle = itemContainerStyle;
}
}
現在我已經設置一個事件引領者丟棄事件和正常工作。如何設置樣式來禁用基於標誌的項目的鼠標懸停和鼠標選擇效果?我發現的大部分代碼都在XAML中。但我需要我的自定義列表框的代碼。任何幫助,將不勝感激。
到目前爲止,這種風格是對我,而且什麼工作及其在XAML我怎麼把它轉換C#代碼,特別是可視狀態和故事板..
<Style x:Key="ListBoxItemStyleTransparentSelect" TargetType="ListBoxItem">
<Setter Property="Background" Value="Transparent"/>
<EventSetter Event="Drop" Handler="listbox1_Drop"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation Duration="0" To=".35" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="fillColor"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="contentPresenter"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected"/>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused"/>
<VisualState x:Name="Unfocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="fillColor" IsHitTestVisible="True" Opacity="0" RadiusY="1" RadiusX="1"/>
<Rectangle x:Name="fillColor2" IsHitTestVisible="True" Opacity="0" RadiusY="1" RadiusX="1"/>
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/>
<Rectangle x:Name="FocusVisualElement" RadiusY="1" RadiusX="1" StrokeThickness="1" Visibility="Collapsed"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我知道。只需看看編輯後的問題。 –