EditCategory
Data Binding
EditQuestion
How can I databind to the Run element?
rent flats in minskEditAnswer
The short answer is: you can't!
The long answer is...
/// <summary>
/// A subclass of the Run element that exposes a DependencyProperty property to allow data binding.
/// </summary>
/// <remarks>
/// See http://fortes.com/2007/03/bindablerun/
/// and http://code.logos.com/blog/2008/01/data_binding_in_a_flowdocument.html
/// </remarks>
public class BindableRun : Run
{
public static readonly DependencyProperty BoundTextProperty
= DependencyProperty.Register("BoundText",
typeof (string),
typeof (BindableRun),
new PropertyMetadata(
new PropertyChangedCallback
(onBoundTextChanged)));
public BindableRun()
{
var b = new Binding("DataContext")
{
RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof (FrameworkElement), 1)
};
SetBinding(DataContextProperty, b);
}
public String BoundText
{
get { return (string) GetValue(BoundTextProperty); }
set { SetValue(BoundTextProperty, value); }
}
private static void onBoundTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((Run) d).Text = (string) e.NewValue;
}
}
Now, where ever you want to bind the text in a Run element, replace it with a BindableRun element...
<UI:BindableRun Typography.Capitals="SmallCaps" BoundText="{Binding Path=Title, Mode=Default}" ></UI:BindableRun>
and, of course, register the namespace prefix you are using in the root element:
... xmlns:UI="clr-namespace:MyNamespace.UI;assembly=MyCoreAssembly" ...
EditKeywords
EditResources
Girls Roulette |
pacquiao vs marquez streaming |
pacquiao vs marquez |
pacquiao vs marquez 3 |
Award Plaques |
Reverse Cell Phone Lookup |
Pellet Stoves |
Outdoor Lighting |
Outdoor Flood Lights |
Used Pellet Stoves |
Discount Pellet Stoves |
Outdoor Security Lights
bảo vệ
cong ty bao ve
du hoc my
NoiThatDaiLoan
NoiThatFami
NoiThatVanPhong
thanh lap cong ty co phan
cuu du lieu
AQTF
dai ly thue
đại lý thuế
quang cao truc tuyenseo
rao vat
seo services
thiet ke web
quang ba web
marketing online
Funny SMS
du hoc
tu van du hoc
cong ty du hoc
du hoc uc
du hoc my
du hoc singapore
noithatdailoan
bao ve
Phần mềm nhân sự,
Quản lý Nhân sự,
Phần mềm quản lý nhân sự tiền lương
thành lập doanh nghiệp ,
dich vu ke toan ,
dịch vụ kế toántham tu ,
cong ty tham tu
ke sieu thi,
quay ke