又过了三天了,词典有了点模样,在遇到难题是睡一觉还是管用的,不知道是不是模拟器的问题汉字的查询不对路,算了,以后再自己完善吧,这东西就到这了先。。。

代码:地址明天给,传了,但是文件设置里还没反应,,

View Code
 1 <phone:PhoneApplicationPage 
2 x:Class="wp7dict.onlinedict"
3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5 xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
6 xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
7 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9 FontFamily="{StaticResource PhoneFontFamilyNormal}"
10 FontSize="{StaticResource PhoneFontSizeNormal}"
11 Foreground="{StaticResource PhoneForegroundBrush}"
12 SupportedOrientations="Portrait" Orientation="Portrait"
13 mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
14 shell:SystemTray.IsVisible="True">
15 <!--LayoutRoot is the root grid where all page content is placed-->
16 <Grid x:Name="LayoutRoot">
17 <Grid.RowDefinitions>
18 <RowDefinition Height="Auto"/>
19 <RowDefinition Height="*"/>
20 </Grid.RowDefinitions>
21 <!--TitlePanel contains the name of the application and page title-->
22 <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
23 <TextBlock x:Name="ApplicationTitle" Text="无限的天空1989" Style="{StaticResource PhoneTextNormalStyle}" Foreground="Blue"/>
24 <TextBlock x:Name="PageTitle" Text="在线Dictionary" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Foreground="#FF008B2B" Width="470" FontSize="68"/>
25 </StackPanel>
26 <!--ContentPanel - place additional content here-->
27 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
28 <TextBox Height="75" HorizontalAlignment="Left" Margin="4,0,0,0" Name="textBox1" Text="" VerticalAlignment="Top" Width="323" BorderBrush="#BF0A0A06" />
29 <Button Content="查找" Height="76" HorizontalAlignment="Left" Margin="329,-2,0,0" Name="search" VerticalAlignment="Top" Width="121" Click="search_Click" BorderBrush="#BF0D050A" Background="#4270F568" Foreground="#F119792F" FontSize="26" />
30 <TextBlock Height="42" HorizontalAlignment="Left" Opacity="0" Margin="14,244,0,0" Name="textBlock1" Text="扩展信息:" Foreground="Red" VerticalAlignment="Top" Width="154" FontSize="26" />
31 <MediaElement Height="50" HorizontalAlignment="Left" Margin="386,232,0,0" Name="SoundOfLetterME" VerticalAlignment="Top" Width="67" AutoPlay="True" Volume="10" />
32 <ListBox Height="163" HorizontalAlignment="Left" Margin="14,75,0,0" Name="listBox1" VerticalAlignment="Top" Width="442" >
33 <TextBlock Name="SoundMarkTextBlock" Text="" Foreground="Red" FontSize="28" TextWrapping="Wrap" />
34 <TextBlock Name="NatureTextBlock" Text="" Foreground="Black" FontSize="28" TextWrapping="Wrap" />
35 <TextBlock Name="ExplainTextBlock" Text="" Foreground="Black" FontSize="28" TextWrapping="Wrap" />
36 </ListBox>
37 <ListBox Height="315" HorizontalAlignment="Left" Margin="14,289,0,0" Name="listBox2" VerticalAlignment="Top" Width="442">
38 <ListBox.ItemTemplate >
39 <DataTemplate >
40 <StackPanel>
41 <TextBlock Text="{Binding orig}" FontSize="28" TextWrapping="Wrap" Foreground="Chocolate"/>
42 <TextBlock Text="{Binding trans}" FontSize="32" TextWrapping="Wrap" Foreground="Black"/>
43 </StackPanel>
44 </DataTemplate>
45 </ListBox.ItemTemplate>
46 </ListBox>
47 <Button Content="" Height="62" Name="SoundOfLetterButton" DataContext="{Binding pron}" Click="SoundOfLetterButton_Click" HorizontalAlignment="Left" Margin="275,73,0,0" VerticalAlignment="Top" Width="62" Opacity="0" >
48 <Button.Background >
49 <ImageBrush ImageSource="/play1.jpg" Stretch="Fill"/>
50 </Button.Background>
51 </Button>
52 </Grid>
53 <Grid.Background>
54 <ImageBrush ImageSource="/backg.jpg" />
55 </Grid.Background>
56 </Grid>
57 </phone:PhoneApplicationPage>

             

 

  1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Net;
5 using System.Windows;
6 using System.Windows.Controls;
7 using System.Windows.Documents;
8 using System.Windows.Input;
9 using System.Windows.Media;
10 using System.Windows.Media.Animation;
11 using System.Windows.Shapes;
12 using Microsoft.Phone.Controls;
13 using System.IO;
14 using System.Xml.Linq;
15 using System.Text;
16 using System.Windows.Data;
17 using System.Text.RegularExpressions;
18 namespace wp7dict
19 {
20 public partial class onlinedict : PhoneApplicationPage
21 {
22 private string mp3url="";
23 public onlinedict()
24 {
25 InitializeComponent();
26
27 }
28
29 private void search_Click(object sender, RoutedEventArgs e)
30 {
31 if (textBox1.Text != null && textBox1.Text != "")
32 {
33 WebClient webc = new WebClient();
34 webc.OpenReadAsync(new Uri("http://dict-co.iciba.com/api/dictionary.php?w=" + textBox1.Text));
35 webc.OpenReadCompleted += new OpenReadCompletedEventHandler(webc_OpenReadCompleted);
36 }
37 }
38
39 void webc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
40 {
41 string webxml, Pos="", Acceptation="";
42 using (StreamReader readxml = new StreamReader(e.Result, Encoding.UTF8))
43 {
44 webxml = readxml.ReadToEnd();
45 }
46 TextReader txtr = new StringReader(webxml);
47 XDocument xdo = XDocument.Load(txtr);
48 #region //汉字查询
49 Regex cn = new Regex("[\u4e00-\u9fa5]+");
50 if (cn.IsMatch(textBox1.Text))
51 {
52 MessageBox.Show("汉译英还有问题就先这样吧!");
53 //var chinese = from query in xdo.Descendants("acceptation")
54 // select new dictionary
55 // {
56 // synonym = query.Element("synonym").Value.ToString()
57 // };
58 //foreach (var i in chinese.ToArray())
59 //{
60 // Pos = Pos + i.synonym.ToString() + '\n';
61 //}
62 //SoundMarkTextBlock.Text = "翻译:" + Pos;
63 }
64 #endregion
65 #region 查找英语和数字
66 else
67 {
68 try
69 {
70 var major = from query in xdo.Descendants("dict")
71 select new dictionary
72 {
73 ps = "音标:" + "/" + query.Element("ps").Value + "/",
74 pron = query.Element("pron").Value
75 };
76 var pos = (from query in xdo.Descendants("pos") select query);//破地方,太费时间了
77 var acceptation = (from query in xdo.Descendants("acceptation") select query);
78 SoundMarkTextBlock.Text = major.ToArray()[0].ps.ToString();
79 foreach (var i in pos.ToArray())
80 {
81 Pos = Pos + i.Value.ToString() + "/";
82 }
83 NatureTextBlock.Text = "词性:" + Pos;
84 foreach (var i in acceptation.ToArray())
85 {
86 Acceptation = Acceptation + i.Value.ToString() + " \\";
87 }
88 ExplainTextBlock.Text = "解释:" + Acceptation;
89 SoundOfLetterButton.Opacity = 1;
90 mp3url = major.ToArray()[0].pron.ToString();
91 }
92 catch (Exception)
93 {
94 SoundOfLetterButton.Opacity = 0;
95 textBox1.Text = "";
96 SoundMarkTextBlock.Text = "音标: 无信息!";
97 NatureTextBlock.Text = "词性: 无信息!";
98 ExplainTextBlock.Text = "解释: 无信息!";
99 }
100 #endregion
101 }
102 try
103 {
104 var dict = from query in xdo.Descendants("sent")
105 select new dictionary
106 {
107 orig = query.Element("orig").Value.ToString(),
108 trans = query.Element("trans").Value.ToString()
109 };
110 listBox2.ItemsSource = dict;
111 textBlock1.Opacity = 1;
112 }
113 catch (Exception)
114 {
115 textBlock1.Opacity = 0;
116 textBox1.Text = "";
117 MessageBox.Show("查找失败!!");
118 }
119
120 }
121
122 private void SoundOfLetterButton_Click(object sender, RoutedEventArgs e)
123 {
124 if (mp3url!="")
125 {
126 SoundOfLetterME.Source =new Uri(mp3url);
127
128 }
129 }
130
131 }
132 }

    真是够呛,在论坛里看到一牛人做了个豆瓣FM(wp7版),太棒了,今后就研究研究怎么整的,咱也做个虾米网的播放器,不知想法靠谱不,希望成功呀!!

作者: 无限的天空1989 发表于 2011-07-25 20:52 原文链接

推荐.NET配套的通用数据层ORM框架:CYQ.Data 通用数据层框架
新浪微博粉丝精灵,刷粉丝、刷评论、刷转发、企业商家微博营销必备工具"