c# - Listbox item mouse double click only works on text not whole line -


my listbox uses datatemplate act on leftdoubleclick:

<usercontrol x:class="x1.xprep.guimodulejobselection.views.contentjobselectionview"          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"          xmlns:l="http://wpflocalizeextension.codeplex.com"          xmlns:classes="clr-namespace:x1.xprep.guimodulejobselection.models"          xmlns:viewmodels="clr-namespace:x1.xprep.guimodulejobselection.viewmodels"          l:localizedictionary.designculture="en"          l:resxlocalizationprovider.defaultassembly="xprep.guimodulejobselection"          l:resxlocalizationprovider.defaultdictionary="resources"           x:name="jobselectioncontent"          mc:ignorable="d"           d:datacontext="{d:designinstance {x:type viewmodels:contentjobselectionviewmodel}, isdesigntimecreatable=true}"          d:designheight="600" d:designwidth="328.5"> <usercontrol.resources>     <resourcedictionary>         <resourcedictionary.mergeddictionaries>             <resourcedictionary source="/xprep.guicommon;component/resources/styles.xaml"/>         </resourcedictionary.mergeddictionaries>          <datatemplate x:key="listboxjobdatatemplate" datatype="{x:type classes:jobforjobselectionviewmodel}">             <textblock horizontalalignment="left" textwrapping="wrap" text="{binding jobdata.jobname}"                         verticalalignment="top">                 <textblock.tooltip>                     <stackpanel height="200" minwidth="200">                         <stackpanel width="200" orientation="vertical" >                             <textblock text="{binding jobdata.jobname}" fontweight="bold"/>                             <image verticalalignment="top" source="{binding previewimagesource}" margin="0,10,0,0"/>                             <textblock text="no preview image available." margin="0,10,0,0">                                 <textblock.style>                                     <style targettype="{x:type textblock}">                                         <style.triggers>                                             <datatrigger binding="{binding path=ispreviewimagemissing}" value="false">                                                 <setter property="visibility" value="hidden"/>                                             </datatrigger>                                         </style.triggers>                                     </style>                                 </textblock.style>                             </textblock>                             <textblock text="{binding jobdata.comment}"/>                         </stackpanel>                     </stackpanel>                 </textblock.tooltip>                 <textblock.inputbindings>                     <mousebinding gesture="leftdoubleclick"                         command="{binding path=datacontext.loadcommand,                          relativesource={relativesource findancestor,ancestortype={x:type usercontrol}}}"/>                 </textblock.inputbindings>             </textblock>         </datatemplate>     </resourcedictionary> </usercontrol.resources> <grid>     <grid.rowdefinitions>         <rowdefinition height="*"/>     </grid.rowdefinitions>     <grid.columndefinitions>         <columndefinition width="auto"/>         <columndefinition width="auto"/>     </grid.columndefinitions>     <listbox itemssource="{binding jobs, mode=twoway}" issynchronizedwithcurrentitem="true"               selecteditem="{binding selectedjob, mode=twoway}" itemtemplate="{dynamicresource listboxjobdatatemplate}"              grid.column="1" grid.row="0" x:name="listboxjobnames" minwidth="200"                               horizontalalignment="stretch"  margin="6" verticalalignment="stretch">         <listbox.inputbindings>             <keybinding key="delete" command="{binding path=datacontext.deletecommand,                          relativesource={relativesource findancestor,ancestortype={x:type usercontrol}}}"/>         </listbox.inputbindings>     </listbox>     <stackpanel grid.column="0" grid.row="0" margin="0" width="100" background="{dynamicresource contextbackgroundbrush}">         <button x:name="jobselectionnewbutton" content="{dynamicresource x1.job.new}" tooltip="{l:loc jobselection_button_new}"                 horizontalalignment="left" margin="6" verticalalignment="top" command="{binding newcommand}" isdefault="true"                 style="{staticresource glossybuttonx1}"/>         <button content="{dynamicresource x1.job.load}" tooltip="{l:loc jobselection_button_load}"                  horizontalalignment="left" margin="6" verticalalignment="top"                 style="{staticresource glossybuttonx1}"                  command="{binding loadcommand}"/>         <button content="{dynamicresource x1.job.rename}" tooltip="{l:loc jobselection_button_rename}"                  horizontalalignment="left" margin="6" verticalalignment="top"                  style="{staticresource glossybuttonx1}"                  command="{binding renamecommand}"/>         <button content="{dynamicresource x1.job.clone}" tooltip="{l:loc jobselection_button_clone}"                  horizontalalignment="left" margin="6" verticalalignment="top"                  style="{staticresource glossybuttonx1}"                  command="{binding clonecommand}"/>         <button content="{dynamicresource x1.common.delete}" tooltip="{l:loc jobselection_button_delete}"                  horizontalalignment="left" margin="6" verticalalignment="top"                 style="{staticresource glossybuttonx1}"                  command="{binding deletecommand}"/>     </stackpanel> </grid> 

the double click works on actual text in items line. can do, let double click work on empty spaces right of item text?

regards rainer

set listboxitems' horizontalcontentalignment = stretch.

for example:

<style targettype="{x:type listboxitem}">         <setter property="horizontalcontentalignment" value="stretch"/> </style> 

in case, above code doesn't work, try setting background of grid transparent (if using grid):

<grid background="transparent"> 

edit:

bind textblock width listboxitem width shown below should fix issue:

<textblock  horizontalalignment="left"              textwrapping="wrap"              text="{binding jobdata.jobname}"              verticalalignment="top"             width="{binding relativesource={relativesource findancestor, ancestortype={x:type listboxitem}}, path=actualwidth}"> 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -