HQuintas Posted April 9, 2012 at 02:25 PM Report #448210 Posted April 9, 2012 at 02:25 PM <Label Content="Print:" Height="157" HorizontalAlignment="Left" Margin="2173,3208,0,0" Name="Label3" VerticalAlignment="Top" Width="173" /> Tem alguma forma simples de pegar os valores Content, Height, Margin,... de um ficheiro xaml?
ribeiro55 Posted April 9, 2012 at 02:27 PM Report #448212 Posted April 9, 2012 at 02:27 PM A partir de onde? Essa linha XAML representa um objecto Label. Podes aceder directamente à propriedade: Label3.Height Label3...... Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips"
HQuintas Posted April 9, 2012 at 02:53 PM Author Report #448226 Posted April 9, 2012 at 02:53 PM Windows form (vb.net) Ler um ficheiro xaml para localizar alguns valores. Dim reader As XmlTextReader = New XmlTextReader("d:\Dados.xaml") Podes aceder directamente à propriedade: Label3.Height Label3...... Não em WPF
ribeiro55 Posted April 9, 2012 at 03:03 PM Report #448229 Posted April 9, 2012 at 03:03 PM XAML é XML. Lê como se fosse XML. Utiliza a classe XDocument e periféricas para o efeito. Dá uma vista de olhos aqui: http://www.jorgepaulino.com/2009/08/vbnet-xml-literals-parte-i.html Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips"
HQuintas Posted April 9, 2012 at 05:34 PM Author Report #448256 Posted April 9, 2012 at 05:34 PM Obrigado, dei a vista de olhos e escrevi o código... Imports System.Xml Public Class Form1 Dim STRxml As String = "D:\teste.xaml" Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim xmlFile As XDocument = XDocument.Load(STRxml) For Each item As XElement In xmlFile...<Grid>.<Label> Debug.WriteLine(item.@Content) Next End Sub End Class mas não sei pq não tá funcionando
ribeiro55 Posted April 9, 2012 at 09:02 PM Report #448284 Posted April 9, 2012 at 09:02 PM <Grid>.<Label> existe três níveis depois da root? Cada ponto representa um nível na hierarquia. Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips"
HQuintas Posted April 10, 2012 at 06:51 AM Author Report #448317 Posted April 10, 2012 at 06:51 AM <Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="3508" Width="2480"> <Grid> <Label Content="Print1:" Height="27" HorizontalAlignment="Left" Margin="37,22,0,0" Name="Label1" VerticalAlignment="Top" Width="53" FontSize="18" FontFamily="SansSerif" /> <Label Content="Print2:" Height="27" HorizontalAlignment="Left" Margin="51,55,0,0" Name="Label2" VerticalAlignment="Top" Width="53" /> <Label Content="Print3:" Height="157" HorizontalAlignment="Left" Margin="2173,3208,0,0" Name="Label3" VerticalAlignment="Top" Width="173" /> </Grid> </Window> Já tentei de várias maneiras, mas nada. Talvez tenha a ver com o ficheiro.
ribeiro55 Posted April 10, 2012 at 10:28 AM Report #448337 Posted April 10, 2012 at 10:28 AM Estava a fazer confusão ali com os pontos como níveis hierárquicos, não são, mas de qualquer forma, parece que o facto do tag Window ter o xmlns, faz com que o XDocument entre em coma. Retirando os namespaces, e os x:attrib, neste caso, o XDocument volta a responder. Experimenta com a outra classe mais antiga: http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips"
HQuintas Posted April 10, 2012 at 12:08 PM Author Report #448362 Posted April 10, 2012 at 12:08 PM Retirando os namespaces, e os x:attrib, neste caso, o XDocument volta a responder. Sim, assim já funciona. Obrigado, vou ver essa classe, mas qualquer das formas já dá para "desenrascar"
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now