导航:首页 > 文字图片 > wpf图片显示文字

wpf图片显示文字

发布时间:2023-01-05 03:58:37

1. WPF 一行上3个控件 左右都是图片 中间是文字 如果文字过长 会覆盖右边的图片 该如何解决

你是要实现这2个iamge控件同时显示同一个图片吗,如果是的话就用数据绑定

2. WPF中什么控件能够既显示图片,又显示文字

其实不改模板就可以实现的呢。因为Button本身是一个ContentControl,所以里面可以塞任何控件的。demo如下: 文本内容

3. 用WPF编程,本来在canvas上显示图像了。如何在上面继续显示文字啊谢谢了

http://stackoverflow.com/questions/13374270/dynamic-data-display-wpf-need-to-add-text-to-canvas-c-sharp

4. (跪求)WPF下的RichTextBox控件下动态添加文字和图片

。。。灵活一点!!!在StackPanl内放image跟RichtextBox两个控件,分别存放图片跟文字不是一样能解决问题吗?

5. c# WPF panel 里面有个listview,listview里面有图片和文字,怎么能将这个listview在打印预览中显示出来

参考资料
http://stackoverflow.com/questions/2322064/how-can-i-proce-a-print-preview-of-a-flowdocument-in-a-wpf-application

6. WPF中哪种组件可以实现以下文字显示效果

WPF中没有直接的控件能够达到这个效果,要自己写控件。给你写了个自定义控件的例子,代码如下:

【代码1】自定义控件RowTextPresenter,提供隔行效果的控件。(示例代码,仅仅封装了FontSize和FontFamily属性,你可以仿造示例自行封装)

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows;

usingSystem.Windows.Controls;

usingSystem.Windows.Data;

usingSystem.Windows.Documents;

usingSystem.Windows.Input;

usingSystem.Windows.Media;

usingSystem.Windows.Media.Imaging;

usingSystem.Windows.Navigation;

usingSystem.Windows.Shapes;

namespaceWpfTextRow.Controls

{

publicclassRowTextPresenter:FrameworkElement

{

privateTextBlock_textPresenter=newTextBlock();

privateDrawingVisual_rowsPresenter=newDrawingVisual();

publicRowTextPresenter()

{

_textPresenter.TextWrapping=TextWrapping.Wrap;

this.AddVisualChild(_rowsPresenter);

this.AddVisualChild(_textPresenter);

}

{

get

{

return2;

}

}

(intindex)

{

if(index==0)return_rowsPresenter;

if(index==1)return_textPresenter;

();

}

protectedoverridevoidOnRender(DrawingContextdrawingContext)

{

base.OnRender(drawingContext);

DrawRows();

}

(SizeavailableSize)

{

_textPresenter.Measure(availableSize);

return_textPresenter.DesiredSize;

}

(SizefinalSize)

{

_textPresenter.Arrange(newRect(newPoint(0,0),finalSize));

returnfinalSize;

}

privatevoidDrawRows()

{

if(_textPresenter==null||_rowsPresenter==null)

return;

varwidth=_textPresenter.ActualWidth;

//通过反射的方式获取折行的行数

varlineCount=_textPresenter.ReflectGetProperty<int>("LineCount");

vardc=_rowsPresenter.RenderOpen();

if(lineCount>1)

{

varoffsetY=0.0;

varbaseValue=(this.AlternationMode==AlternationMode.Even)?1:0;

for(inti=0;i<lineCount;i++)

{

//通过反射的方式获取每一行的高度

varlineMetrics=_textPresenter.ReflectCall("GetLine",i);

varlineHeight=lineMetrics.ReflectGetProperty<double>("Height");

//判断奇偶行,绘制背景块

if(i%2==baseValue)

{

dc.DrawRectangle(this.AlternationBackground,null,newRect(0,offsetY,width,lineHeight));

}

offsetY+=lineHeight;

}

}

dc.Close();

}

#regionFontSize

=

TextElement.FontSizeProperty.AddOwner(typeof(RowTextPresenter),

newFrameworkPropertyMetadata((double)12.0));

publicdoubleFontSize

{

get{return(double)GetValue(FontSizeProperty);}

set{SetValue(FontSizeProperty,value);}

}

#endregion

#regionFontFamily

///<summary>

///FontFamilyDependencyProperty

///</summary>

=

TextElement.FontFamilyProperty.AddOwner(typeof(RowTextPresenter),

newFrameworkPropertyMetadata(null));

///<summary>

///.Thisdependencyproperty

///indicates....

///</summary>

publicFontFamilyFontFamily

{

get{return(FontFamily)GetValue(FontFamilyProperty);}

set{SetValue(FontFamilyProperty,value);}

}

#endregion

#regionText

=

DependencyProperty.Register("Text",typeof(string),typeof(RowTextPresenter),

newFrameworkPropertyMetadata(null,

.AffectsRender,

newPropertyChangedCallback(OnTextChanged)));

publicstringText

{

get{return(string)GetValue(TextProperty);}

set{SetValue(TextProperty,value);}

}

(DependencyObjectd,)

{

((RowTextPresenter)d).OnTextChanged(e);

}

()

{

_textPresenter.Text=(string)e.NewValue;

}

#endregion

#regionAlternationBackground

=

DependencyProperty.Register("AlternationBackground",typeof(Brush),typeof(RowTextPresenter),

newFrameworkPropertyMetadata(null,

.None,

newPropertyChangedCallback()));

{

get{return(Brush)GetValue(AlternationBackgroundProperty);}

set{SetValue(AlternationBackgroundProperty,value);}

}

privatestaticvoid(DependencyObjectd,)

{

((RowTextPresenter)d).(e);

}

protectedvirtualvoid()

{

this.DrawRows();

}

#endregion

#regionAlternationMode

=

DependencyProperty.Register("AlternationMode",typeof(AlternationMode),typeof(RowTextPresenter),

newFrameworkPropertyMetadata(AlternationMode.Even,

.AffectsRender));

{

get{return(AlternationMode)GetValue(AlternationModeProperty);}

set{SetValue(AlternationModeProperty,value);}

}

#endregion

}

///<summary>

///跳行模式

///</summary>

publicenumAlternationMode

{

///<summary>

///从偶数行开始

///</summary>

Even,

///<summary>

///从奇数行开始

///</summary>

Odd

}

}

【代码2】ReflectionService,提供反射功能的工具类

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Reflection;

namespaceWpfTextRow.Controls

{

{

=

BindingFlags.Public|

BindingFlags.NonPublic|

BindingFlags.Instance;

<T>(thisobjecttarget,stringpropertyName)

{

vartype=target.GetType();

varpropertyInfo=type.GetProperty(propertyName,ReflectionFlags);

return(T)propertyInfo.GetValue(target,null);

}

publicstaticobjectReflectCall(thisobjecttarget,stringmethodName,paramsobject[]args)

{

vartype=target.GetType();

varpropertyInfo=type.GetMethod(methodName,ReflectionFlags);

returnpropertyInfo.Invoke(target,args);

}

}

}

【代码3】使用的代码

<l:="LightGreen"

FontSize="14"

Text="BEIJING—AstudybyChina'-onrules,.Thestudy,meantforinternaldistribution,-equipmentmakers,suchasHuaweiTechnologiesCo.andZTECorp.,.subsidiesbyfundingresearch-and-developmentprojects,,saidtheperson,whodeclinedtobenamed."/>

【效果图片】

阅读全文

与wpf图片显示文字相关的资料

热点内容
明星烫头发型图片 浏览:673
如何p图去掉图片上的文字 浏览:995
图片上如何加字 浏览:685
女式中短发型图片大全 浏览:968
一张图片男生看着女生 浏览:662
美女拧螺丝图片 浏览:804
女孩卡通帅气图片 浏览:960
手机怎么编辑图片k值 浏览:276
伤心的图片男生霸气 浏览:772
图片每日美女 浏览:241
领导发型图片 浏览:527
大型绞肉机图片及价格 浏览:898
长脸寸头发型图片男 浏览:229
简单的动画图片怎么画有方法 浏览:508
美女穿蕾丝内裤约图片 浏览:988
如何把朋友圈的图片变得模糊 浏览:800
播放女生么奇男生的图片 浏览:360
word上怎样调整图片 浏览:1001
ps如何复制一个图片上的字 浏览:91
好看简单的动漫动物图片 浏览:12