2013-06-05 1 views
0

나는 모든 게시물을 읽었으며 내 질문에 대한 대답 일지 모르지만 개념을 이해하지 못했기 때문에 간단한 질문에 답변 할 수 있기를 바랍니다. 내가 텍스트 블록에서 텍스트를 검색하고 내 텍스트에 음성 코드를 먹이 싶습니다.코드에서 XAML TextBlock에서 데이터를 검색하는 방법은 무엇입니까?

if (DataContext == null) 
{ 
      string selectedIndex = ""; 
      if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex)) 
    `enter code here`   { 
       int index = int.Parse(selectedIndex); 
       DataContext = App.ViewModel.Items[index]; 
       string saythis = "*here is where my question comes in - how do I get the string from the TextBlock in ControlPanel?*" 
       Speaker(saythis); 
       saythis = "here is where my question comes in - how do I get the string from the TextBlock in ControlPanel2?" 
       Speaker(saythis); 
      } 
     } 
    } 
    async void Speaker(string words) 
    { 
     SpeechSynthesizer synth = new SpeechSynthesizer(); 
     await synth.SpeakTextAsync(words); 
    } 

데이터 바인딩 모델에서 온 XAML은 다음과 같습니다 : 내가 실제로 이해한다면

<!--TitlePanel contains the name of the application and page title--> 
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> 
     <TextBlock Text="Gr8Oz software" Style="{StaticResource PhoneTextNormalStyle}"/> 
     <TextBlock Text="{Binding Heading}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> 
    </StackPanel> 

    <!--ContentPanel contains details text. Place additional content here--> 
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
     <TextBlock Text="{Binding Login}" TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}"/> 

    </Grid> 
    <Grid x:Name="ContentPanel2" Margin="12,123,12,10" Grid.RowSpan="2"> 

     <TextBlock Text="{Binding Password}" TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,10,12,0" Grid.ColumnSpan="2" Grid.RowSpan="2"/> 
    </Grid> 
+0

무엇이 잘못 되었나요? –

답변

0

확실하지

의 도움이 필요합니다 코드는 이것이다 질문은 맞습니다.하지만 텍스트에서 텍스트를 가져 오는 방법에 관한 것이라면 두 TextBlocks의 Text 속성이 일부 속성 Login에 바인딩으로,

var firstText = textBlock1.Text; 
var secondText = textBlock2.Text; 

그러나 :

<Grid ...> 
    <TextBlock x:Name="textBlock1" Text="{Binding Login}" ..../> 
</Grid> 
<Grid ...> 
    <TextBlock x:Name="textBlock2" Text="{Binding Password}" .../> 
</Grid> 

코드에서 : 단순히 x:Name를 설정 한 다음 코드에서 해당 멤버에 액세스 할 이유 IC TextBlocks, 그리고 Password, 왜 직접 텍스트를 가져 오지 않습니까?

+0

맞습니다. 내 길에와 주셔서 감사합니다. –

관련 문제