Jump to content
HQuintas

xaml obter valores das propriedades

Recommended Posts

HQuintas

  <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?

Share this post


Link to post
Share on other sites
ribeiro55

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"

Share this post


Link to post
Share on other sites
HQuintas

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

Share this post


Link to post
Share on other sites
HQuintas

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 

Share this post


Link to post
Share on other sites
ribeiro55

<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"

Share this post


Link to post
Share on other sites
HQuintas

<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.

Share this post


Link to post
Share on other sites
ribeiro55

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"

Share this post


Link to post
Share on other sites
HQuintas

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"

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.