导航:首页 > 文字图片 > 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图片显示文字相关的资料

热点内容
简单插画小清新作品图片 浏览:554
怎样把图片的底色变白文字变清晰 浏览:528
动漫黑白霸气图片女生 浏览:461
wps图片如何显示页码 浏览:394
图片中有一个是女孩图片 浏览:478
美甲图片2017款式简单 浏览:208
word里怎么把图片转正 浏览:240
叶罗丽娃娃最新图片和衣服 浏览:707
女孩子听盘卡通人物图片 浏览:361
怎么把图片模糊变清晰度 浏览:984
抖音伤感网图片女生 浏览:853
图片文字鹏 浏览:749
丝巾搭配发型图片 浏览:127
塑料鱼桶价格及图片 浏览:295
花木兰发型儿童图片 浏览:563
手镯品牌价格及图片 浏览:383
霸气女生动漫图片大全 浏览:804
短发漫画女生背影图片 浏览:694
初一男生图片背影或侧脸 浏览:872
如何在病理图片上加标尺 浏览:460