5
我有一個項目,我希望能夠有一些控件的工具提示,這些控件將包含一些控件,如文本框和日期選擇器。這個想法是有一些有限的圖形彈出式窗口,但有一些控制互動。WPF工具提示與控件
我知道如何向控件添加「正常」工具提示,但是當您移動時,工具提示會消失,因此我無法與其進行交互。
這是可能的嗎?如果是的話,如果沒有,有沒有其他辦法呢?
感謝
我有一個項目,我希望能夠有一些控件的工具提示,這些控件將包含一些控件,如文本框和日期選擇器。這個想法是有一些有限的圖形彈出式窗口,但有一些控制互動。WPF工具提示與控件
我知道如何向控件添加「正常」工具提示,但是當您移動時,工具提示會消失,因此我無法與其進行交互。
這是可能的嗎?如果是的話,如果沒有,有沒有其他辦法呢?
感謝
您應該使用Popup
代替ToolTip
例。當在TextBox
鼠標移動和停留,只要鼠標在TextBox
或Popup
<TextBox Name="textBox"
Text="Popup On Mouse Over"
HorizontalAlignment="Left"/>
<Popup PlacementTarget="{Binding ElementName=textBox}"
Placement="Bottom">
<Popup.IsOpen>
<MultiBinding Mode="OneWay" Converter="{StaticResource BooleanOrConverter}">
<Binding Mode="OneWay" ElementName="textBox" Path="IsMouseOver"/>
<Binding RelativeSource="{RelativeSource Self}" Path="IsMouseOver" />
</MultiBinding>
</Popup.IsOpen>
<StackPanel>
<TextBox Text="Some Text.."/>
<DatePicker/>
</StackPanel>
</Popup>
公開賽是使用BooleanOrConverter
public class BooleanOrConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
foreach (object booleanValue in values)
{
if (booleanValue is bool == false)
{
throw new ApplicationException("BooleanOrConverter only accepts boolean as datatype");
}
if ((bool)booleanValue == true)
{
return true;
}
}
return false;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
更新
給一個Popup
被打開爲DataGrid
中的單元格執行此操作,您有幾個選項。其中兩個是在DataTemplates
內部添加Popup
的DataGridTemplateColumn
,或者您可以將其添加到DataGridCell Template
。這是後面的例子。它會要求你在DataGrid
<DataGrid SelectionMode="Single"
SelectionUnit="Cell"
...>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid>
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<Popup PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Placement="Right"
IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected}">
<StackPanel>
<TextBox Text="Some Text.."/>
<DatePicker/>
</StackPanel>
</Popup>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.CellStyle>
<!--...-->
</DataGrid>
設置的SelectionMode =「單」和SelectionUnit =「細胞」這個問題能在DatagridRow完成,或者我應該使用TemplateColumn中與文本塊呢? –
當然,你想如何工作? 「Popup」何時應該可見等? –
我想在選中單元格時打開彈出窗口。完成後,帶有選項的小型彈出窗口將可用。 –