我在textblock wpf中使用工具提示遇到了一些麻烦。
完成1个任务后,如果任务出错,我想使用工具提示更新错误信息。但是工具提示永远不会在完成时显示。请帮我 。
谢谢
这是我的代码
C#代码
if (status == "Error")
{
LogCreateSite item = (LogCreateSite)gridLog.Items[rowIndex];
item.ErrorInfo = "Error";
DataTemplate template = cellTitle.ContentTemplate;
Canvas canvas = (Canvas)template.LoadContent();
TextBlock txtError = (TextBlock)canvas.Children[1];
ToolTip toolTip = new ToolTip();
toolTip.Content = "asdfasdf";
txtError.ToolTip = toolTip;
txtError.UpdateLayout();
}
还有我的Xaml:
<DataTemplate x:Key="error">
<Canvas Margin="10,15,0,0">
<!--<Ellipse Fill="#FF5050" Width="12" Height="12">
</Ellipse>-->
<Viewbox Width="16" Height="16">
<Frame Source="../Icon/Error_16.xaml" />
</Viewbox>
<TextBlock Text="Error" Margin="25,-3,0,0">
</TextBlock>
<TextBlock Cursor="Hand" Name="txtErrorInfo" ToolTip="{Binding ErrorInfo, Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" FontSize="14" Text="?" Margin="60,-3,0,0" FontWeight="Bold" Foreground="Blue">
</TextBlock>
</Canvas>
</DataTemplate>
参考方案
您需要对工具提示进行绑定,以向用户显示错误/消息。
请通过本教程进行wpf绑定。 Introduction to WPF data binding来自WPF教程。
您的XAML应该像这样才能正确绑定。
Name="txtErrorInfo" ToolTip="{binding path=error mode=OneWay UpdateSourceTrigger=PropertyChanged}"
更改应显示给用户的属性时,需要提及mode
和UpdateSourceTrigger
。
我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…
改造正在返回一个空的响应主体 - java我正在尝试使用Retrofit和Gson解析一些JSON。但是,我得到的响应机构是空的。当我尝试从对象中打印信息时,出现NullPointerException。我确保URL正确,并且我也确保POJO也正确。我正在使用jsonschema2pojo来帮助创建POJO类。这是我要解析的JSON{ "?xml": { "@versi…
Div单击与单选按钮相同吗? - php有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date…
每个文件合并后添加换行 - python我有很多类似以下内容的JSON文件:例如。1.json{"name": "one", "description": "testDescription...", "comment": ""} test.json{"name"…
Ajax表单未获得结果 - javascript我有一个带有搜索功能的主页。从主页搜索可以正常工作,但是当我尝试使用ajax表单(在url.com/search?id=biology上)再次搜索时,我被重定向到404页面,提示未找到/Search。主页上的表格:@using (Html.BeginForm("Index", "Search", new { Retur…