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."/>
【效果圖片】