5
ho questo:Set stile di TextBlock programatically
var MyText = new TextBlock();
MyText.Text = "blah";
MyText.Style = /* ??? */;
In XAML, è possibile impostare uno stile come questo:
<TextBlock Text="blah" Style="{ThemeResource ListViewItemTextBlockStyle}"/>
Ma come faccio a fare questo in 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?)
Quando ho provato (Style)this.FindResource("ListViewItemTextBlockStyle");
e (Style)App.Current.FindResource("ListViewItemTextBlockStyle")
ho ottenuto questi errori.
qualcosa del tipo 'MyText.Style = (Style) this.FindResource ("ListViewItemTextBlockStyle");' dove questa è la vostra finestra o l'elemento che contiene la risorsa o '(Style) App .Current.FindResource ("ListViewItemTextBlockStyle") ' –
http://stackoverflow.com/questions/1729368/creating-a-style-in-code-behind e http://stackoverflow.com/questions/10686917/setting-the -style-property-of-a-wpf-label-in-code –
@decoherence nessuno dei due ha funzionato per me. – Zudo