Hi
I implemented a method in my app for json files in folder to read in a message box when i try to run in the emulator it throws the following exception "An exception of type 'System.NotImplementedException' occurred in DevotionJson.DLL but was not handled in user code"
Kindly view my code below for necessary correction
CustomMessageBox cmb;
private void openMsgBox(object sender, RoutedEventArgs e)
{
// create new Stack panel
StackPanel sp = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Vertical };
//get policy text from file
string policy = getPolicy();
//Create new label
TextBlock tb = new TextBlock()
{
Text =policy,
TextWrapping = TextWrapping.Wrap,
FontSize = 25,
};
//Create new Scroll viewer
ScrollViewer sv = new ScrollViewer()
{
VerticalScrollBarVisibility=ScrollBarVisibility.Auto,
Height=500,
};
// add texblock in scroll viewer
sv.Content = tb;
//Add the controls to stack panel
sp.Children.Add(sv);
// Create new Custom Message Box instance
cmb = new CustomMessageBox()
{
// Set its content to our Stack Panel
Content = sp,
Opacity = 0.98,
// Left button of message box Button
LeftButtonContent = "Accepts",
//Right button of message Box
RightButtonContent="Reject",
};
//Handle msg box click
cmb.Dismissing += cmb_Dismissing;
//Show the message box...
cmb.Show();
}
private string getPolicy()
{
throw new NotImplementedException();
}
void cmb_Dismissing(object sender, DismissingEventArgs e)
{
if (e.Result==CustomMessageBoxResult.LeftButton)
{
MessageBox.Show("Now you can use this app.");
}
else
{
//do what you want
MessageBox.Show("It's mandatory to accepts the T&C to use this app. Exiting from app.");
App.Current.Terminate();
}
}
public string getPolicy(string JsonfilePath)
{
string strText = "This";
using (StreamReader r = new StreamReader("BibleInYear/Bible1.json"))
{
string json = r.ReadToEnd();
dynamic array = JsonConvert.DeserializeObject(json);
//... read text from json file
}
return strText;
}
I await your response and thank you in advance
Loading
VulpesPosted Jan 23, 2015, 9:09 AM
To do that, just change this line:
return d[0];
to (say) this:
return d[0].ReadText;
VulpesPosted Jan 23, 2015, 10:27 AM
JOHN JOHNNNYPosted Jan 23, 2015, 10:01 AM
JOHN JOHNNNYPosted Jan 23, 2015, 8:23 AM
When i ran the build i got this error "Cannot implicitly convert type 'DevotionJson.Devotion' to 'string'"
//This is my class
public class Devotion
{
public string Date { get; set; }
public string Title { get; set; }
public string Verse { get; set; }
[JsonProperty("Read Chapter")]
public string ReadChapter { get; set; }
[JsonProperty("Read Text")]
public string ReadText { get; set; }
[JsonProperty("Bible In One Year")]
public string BibleInOneYear { get; set; }
public string Message { get; set; }
public string Notes { get; set; }
public override string ToString()
{
string[] props = new string[8];
props[0] = "DATE - " + Date;
props[1] = "TITLE - " + Title;
props[2] = "VERSE - " + Verse;
props[3] = "READ CHAPTER - " + ReadChapter;
props[4] = "READ TEXT - " + ReadText;
props[5] = "BIBLE IN ONE YEAR - " + BibleInOneYear;
props[6] = "MESSAGE - " + Message;
props[7] = "NOTES - " + Notes;
return String.Join("\r\n\r\n", props);
}
}
//This is my xaml.cs
CustomMessageBox cmb;
private void openMsgBox(object sender, RoutedEventArgs e)
{
// create new Stack panel
StackPanel sp = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Vertical };
//get policy text from file
string devotion = getDevotion("MyDevotion/Devotion1.json");
//Create new label
TextBlock tb = new TextBlock()
{
Text = devotion,
TextWrapping = TextWrapping.Wrap,
FontSize = 25,
};
//Create new Scroll viewer
ScrollViewer sv = new ScrollViewer()
{
VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
Height = 700,
};
// add texblock in scroll viewer
sv.Content = tb;
//Add the controls to stack panel
sp.Children.Add(sv);
cmb = new CustomMessageBox()
{
// Set its content
Content = sp,
Opacity = 0.9,
// Left button of message box Button
LeftButtonContent = "Back",
};
//Show the message box...
cmb.Show();
}
public string getDevotion(string JsonfilePath)
{
Devotion[] d = null;
using (StreamReader r = new StreamReader(JsonfilePath))
{
string json = r.ReadToEnd();
d = JsonConvert.DeserializeObject
}
return d[0];//**Error here**
}
Kindly help
VulpesPosted Jan 23, 2015, 7:07 AM
JOHN JOHNNNYPosted Jan 23, 2015, 2:26 AM
When i ran it in the emulator it shows no error but the content of my json file is not appearing when i clicked the message box it shows blank with no content. I have created a class for the json before which is BibleData.cs, view my code below for neccessary correction
//BibleData.cs
public partial class BibleData
{
public string Date { get; set; }
[JsonProperty("Bible Chapter")]
public string BibleChapter { get; set; }
[JsonProperty("Bible Content")]
public string BibleContent { get; set; }
public override string ToString()
{
string[] props = new string[3];
props[0] = "DATE - " + Date;
props[1] = "Bible Chapter - " + BibleChapter;
props[2] = "Bible Content - " + BibleContent;
return String.Join("\r\n\r\n", props);
}
}
//xaml.cs
CustomMessageBox cmb;
private void openMsgBox(object sender, RoutedEventArgs e)
{
// create new Stack panel
StackPanel sp = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Vertical };
//get policy text from file
string policy = getPolicy("BibleInYear/Bible1.json");
//Create new label
TextBlock tb = new TextBlock()
{
Text =policy,
TextWrapping = TextWrapping.Wrap,
FontSize = 25,
};
//Create new Scroll viewer
ScrollViewer sv = new ScrollViewer()
{
VerticalScrollBarVisibility=ScrollBarVisibility.Auto,
Height=500,
};
// add texblock in scroll viewer
sv.Content = tb;
//Add the controls to stack panel
sp.Children.Add(sv);
// Create new Custom Message Box instance
cmb = new CustomMessageBox()
{
// Set its content to our Stack Panel
Content = sp,
Opacity = 0.98,
// Left button of message box Button
LeftButtonContent = "Accepts",
//Right button of message Box
RightButtonContent="Reject",
};
//Handle msg box click
cmb.Dismissing += cmb_Dismissing;
//Show the message box...
cmb.Show();
}
void cmb_Dismissing(object sender, DismissingEventArgs e)
{
if (e.Result==CustomMessageBoxResult.LeftButton)
{
MessageBox.Show("Now you can use this app.");
}
else
{
//do what you want
MessageBox.Show("It's mandatory to accepts the T&C to use this app. Exiting from app.");
App.Current.Terminate();
}
}
public string getPolicy(string JsonfilePath)
{
string strText = null;
using (StreamReader r = new StreamReader(JsonfilePath))
{
string json = r.ReadToEnd();
dynamic array = JsonConvert.DeserializeObject(json);
//... read text from json file
}
return strText;
}
Thank you in advance
VulpesPosted Jan 22, 2015, 6:47 PM