5
mam to:Ustaw styl TextBlock programowo
var MyText = new TextBlock();
MyText.Text = "blah";
MyText.Style = /* ??? */;
w XAML, mogę ustawić styl takiego:
<TextBlock Text="blah" Style="{ThemeResource ListViewItemTextBlockStyle}"/>
Ale jak mam to zrobić w C#?
EDIT:
Error 1 'Windows.UI.Xaml.Application' does not contain a definition for 'FindResource' and no extension method 'FindResource' accepting a first argument of type 'Windows.UI.Xaml.Application' could be found (are you missing a using directive or an assembly reference?)
Error 1 'Geodropper.HubPage' does not contain a definition for 'FindResource' and no extension method 'FindResource' accepting a first argument of type 'Geodropper.HubPage' could be found (are you missing a using directive or an assembly reference?)
Kiedy próbowałem (Style)this.FindResource("ListViewItemTextBlockStyle");
i (Style)App.Current.FindResource("ListViewItemTextBlockStyle")
mam te błędy.
coś takiego jak 'MyText.Style = (Style) this.FindResource ("ListViewItemTextBlockStyle");' gdzie jest to Twoja okno lub element zawierający zasób lub '(styl) App .Current.FindResource ("ListViewItemTextBlockStyle") ' –
http://stackoverflow.com/questions/1729368/creating-a-style-in-code-behind i http://stackoverflow.com/questions/10686917/setting-the -style-property-of-a-wpf-label-in-code –
@decoherence żadne z tych nie zadziałało dla mnie. – Zudo