導航:首頁 > 文字圖片 > 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圖片顯示文字相關的資料

熱點內容
噪音如何防治圖片 瀏覽:12
淘寶搜出來圖片點進去怎麼變了 瀏覽:599
男生說自己累的搞笑圖片 瀏覽:875
word怎麼設置圖片襯於文字下面 瀏覽:210
如何將ps中的圖片摳圖 瀏覽:696
女生節愛自己的圖片 瀏覽:178
剪紙圖片簡單熊貓 瀏覽:867
日本白色衣服圖片 瀏覽:744
天門山滑翔翼女孩劉安圖片資料 瀏覽:71
風法米拉2高清圖片 瀏覽:881
銀錠價格表及圖片大全 瀏覽:502
特異構成圖片作業簡單 瀏覽:266
動漫女人物大全圖片 瀏覽:566
小倉鼠表情包圖片大全 瀏覽:338
金沙手串價格及圖片 瀏覽:450
百度識圖保存的圖片怎麼刪除 瀏覽:771
iu紅色洋氣衣服圖片 瀏覽:893
熱巴跑男衣服圖片 瀏覽:401
中式博物架圖片大全 瀏覽:305
簡單的老鷹畫圖片 瀏覽:168