使用WPF,我有ListBox一个DataTemplate内部控件.相关的XAML代码如下所示:
<ListBox Name="_todoList" Grid.Row="1" BorderThickness="2"
Drop="todoList_Drop" AllowDrop="True"
HorizontalContentAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
AlternationCount="2">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" Checked="CheckBox_Check" />
<TextBlock Name="descriptionBlock"
Grid.Column="1"
Text="{Binding Description}"
Cursor="Hand" FontSize="14"
ToolTip="{Binding Description}"
MouseDown="TextBlock_MouseDown" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
我想要做的是TextBlock对(双)点击做出响应,将其变成一个TextBox.然后,用户可以编辑描述,然后按返回或更改焦点进行更改.
我尝试TextBox在与TextBlock相同的位置添加一个元素并使其可见Collapsed,但我不知道TextBox当用户点击一个元素时如何向右导航TextBlock.也就是说,我知道用户点击了一定的TextBlock,现在该 TextBox我说明了什么?
任何帮助将非常感激,
-Ko9
我已经在C#WinForms中创建了一个控件,并且在我的OnPaint()处理程序中自定义绘图文本.使用我的表单中的以下代码将字体设置为Courier New:
FontFamily family = new FontFamily("Courier New");
this.myControl.Font = new Font(family, 10);
Run Code Online (Sandbox Code Playgroud)
在控件本身,字符串存储在realText,我使用以下代码将其绘制到屏幕:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawString(realText, Font, new SolidBrush(ForeColor), ClientRectangle);
}
Run Code Online (Sandbox Code Playgroud)
一些随机示例文本的结果如下所示:http: //img219.imageshack.us/img219/1778/courier.png
如果你放大,你可以看到,例如,第一个'as'之间的空间不同于第二个'as'之间的空格(1个像素对2个像素).有没有人知道可能导致这种情况的原因,或者我如何防止它发生?我使用不同的字体绘制的间距有很多类似的怪异,但我认为它们都是同一问题的结果.
提前感谢您的任何想法.
c# ×2
controls ×1
datatemplate ×1
drawstring ×1
listbox ×1
onpaint ×1
winforms ×1
wpf ×1
xaml ×1