Mouseover تسليط الضوء على أسلوب العودة إلى الافتراضي بعد ثانية (ناتجة عن Aero؟)

StackOverflow https://stackoverflow.com/questions/250622

سؤال

أحاول تصميم comboBoxes الخاص بي لمطابقة بقية واجهة المستخدم ، لكنني أواجه مشاكل في تسليط الضوء على IsMouseover. يسلط الضوء على اللون الذي أحدده لثانية ثم يتلاشى إلى اللون الافتراضي ، وهو نوع من التأثير الرائع ولكن ليس ما سأذهب إليه. ها هو أسلوبي:

<Style TargetType="ComboBox">
    <Style.Triggers>
        <Trigger Property="ComboBox.IsMouseOver" Value="True">
            <Setter Property = "Background" Value="Red"/>
        </Trigger>
    </Style.Triggers>
</Style>

ماذا يمكنني أن أفعل لجعل لون الخلفية يبقى؟

هل كانت مفيدة؟

المحلول

تكمن المشكلة بالفعل في القالب الافتراضي لـ Combobox. كما ترى العاكس لفتح العرض التقديمي framework.aero ، يمكنك إلقاء نظرة على فئة Buttonchrome. هناك طريقة تسمى onRenderMouseoverchanged التي تخفي الخلفية الحمراء.

على الرغم من أنه كثير من العمل ، بالنسبة إلى Combobox على الأقل ، فمن المحتمل أن ترغب في تجاوز القالب الافتراضي لـ Combobox. يمكنك الحصول على الفكرة الأساسية لما يشبه Combobox Temlpate عن طريق الاستخدام أرني القالب أو يمزج.

يمكنك استخدام نفس الأسلوب لتجاوز القالب.

<Style TargetType="{x:Type ComboBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ComboBox}">
                <!-- Template Here -->
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

نصائح أخرى

يمكنك تجاوز هذا السلوك عن طريق الحصول على نسخة من القالب الافتراضي من مصمم WPF Visual Studio ومن ثم في ComboBoxReadOnlyToggleButton Style التعليق على قسم Buttonchrome واستبداله بحدود. فيما يلي رابط للموقع حيث وجدت الحل - http://www.scriptscoop.net/t/d346cf01d844/cc-wpf-combobox-mouse-over.html

ها هو مقتطف الرمز الخاص بي

<Style x:Key="ComboBoxReadonlyToggleButton" TargetType="{x:Type ToggleButton}">
  <Setter Property="OverridesDefaultStyle" Value="true"/>
  <Setter Property="IsTabStop" Value="false"/>
  <Setter Property="Focusable" Value="false"/>
  <Setter Property="ClickMode" Value="Press"/>
  <Setter Property="Background" Value="Transparent"/>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type ToggleButton}">
        <!-- Replace the ButtonChrome - this eliminated the following
             problem:  When the mouse was moved over the ComboBox
             the color would change to the color defined in ___ but 
             then would  
             immediately change to the default Aero blue
             gradient background of 2 powder blue colors  - 
             Had to comment out the          
             below code and replace it as shown
             <Themes:ButtonChrome x:Name="Chrome" BorderBrush="                 {TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" SnapsToDevicePixels="true">
               <Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
                 <Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/>
               </Grid>
             </Themes:ButtonChrome>-->

         <!-- Here is the code to replace the ButtonChrome code -->
         <Border x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
           <Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
             <Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/>
           </Grid>
         </Border>
       <!-- End of code to replace the Button Chrome -->

لقد أضفت أيضًا بعض التعليمات البرمجية لتغيير لون الخلفية إلى Darkorange - دخل هذا الرمز إلى ControlTemplate (في القسم) لأسلوب Combobox.

<!-- Hover Code - Code that was added to change the ComboBox background 
     color when the use hovers over it with the mouse -->
<Trigger Property="IsMouseOver" Value="True">
   <Setter Property="Background" Value="DarkOrange"></Setter>
</Trigger>
<!-- Hover Code - End -->
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top