<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>数据绑定 on 菠萝学</title><link>https://www.poloxue.com/docs/gofyne/07-binding/</link><description>Recent content in 数据绑定 on 菠萝学</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><managingEditor>poloxue123@gmail.com (POLO XUE)</managingEditor><webMaster>poloxue123@gmail.com (POLO XUE)</webMaster><copyright>© 2026 POLO XUE</copyright><lastBuildDate>Thu, 21 May 2026 19:07:14 +0800</lastBuildDate><atom:link href="https://www.poloxue.com/docs/gofyne/07-binding/index.xml" rel="self" type="application/rss+xml"/><item><title>数据绑定</title><link>https://www.poloxue.com/docs/gofyne/07-binding/00-overview/</link><pubDate>Wed, 02 Apr 2025 00:00:00 +0000</pubDate><author>poloxue123@gmail.com (POLO XUE)</author><guid>https://www.poloxue.com/docs/gofyne/07-binding/00-overview/</guid><description>&lt;p&gt;数据绑定是 Fyne 工具包的一个强大新功能，它在版本 &lt;code&gt;v2.0.0&lt;/code&gt; 中引入。通过使用数据绑定，我们可以避免手动管理许多标准对象，如 &lt;code&gt;Label&lt;/code&gt;、&lt;code&gt;Button&lt;/code&gt; 和 &lt;code&gt;List&lt;/code&gt;。&lt;/p&gt;
&lt;p&gt;内置绑定支持许多原始类型（如 &lt;code&gt;Int&lt;/code&gt;、&lt;code&gt;String&lt;/code&gt;、&lt;code&gt;Float&lt;/code&gt; 等）、列表（例如 &lt;code&gt;StringList&lt;/code&gt;、&lt;code&gt;BoolList&lt;/code&gt;）以及 &lt;code&gt;Map&lt;/code&gt; 和 &lt;code&gt;Struct&lt;/code&gt; 绑定。每种类型都可以使用简单的构造函数创建。例如，要使用零值创建一个新的字符串绑定，可以使用 &lt;code&gt;binding.NewString()&lt;/code&gt;。你可以使用 &lt;code&gt;Get&lt;/code&gt; 和 &lt;code&gt;Set&lt;/code&gt; 方法获取或设置大多数数据绑定的值。&lt;/p&gt;</description></item><item><title>简单绑定</title><link>https://www.poloxue.com/docs/gofyne/07-binding/01-simple/</link><pubDate>Sat, 05 Apr 2025 00:00:00 +0000</pubDate><author>poloxue123@gmail.com (POLO XUE)</author><guid>https://www.poloxue.com/docs/gofyne/07-binding/01-simple/</guid><description>&lt;p&gt;绑定控件的最简单形式是将绑定项作为值传递给它，而不是静态值。许多控件提供了一个&lt;code&gt;WithData&lt;/code&gt;构造函数，它将接受一个类型化的数据绑定项。要设置绑定，你需要做的就是传递正确的类型。&lt;/p&gt;</description></item><item><title>双向绑定</title><link>https://www.poloxue.com/docs/gofyne/07-binding/02-twoway/</link><pubDate>Tue, 08 Apr 2025 00:00:00 +0000</pubDate><author>poloxue123@gmail.com (POLO XUE)</author><guid>https://www.poloxue.com/docs/gofyne/07-binding/02-twoway/</guid><description>&lt;p&gt;到目前为止，我们已经看到了数据绑定作为一种方式来保持用户界面元素更新。然而，更常见的需求是从UI控件更新值并保持数据在各处都是最新的。值得庆幸的是，Fyne提供的绑定是“双向”的，这意味着值既可以被推入其中也可以被读出。数据的更改将被通知到所有连接的代码，无需任何额外的代码。&lt;/p&gt;</description></item><item><title>数据转换</title><link>https://www.poloxue.com/docs/gofyne/07-binding/03-conversion/</link><pubDate>Fri, 11 Apr 2025 00:00:00 +0000</pubDate><author>poloxue123@gmail.com (POLO XUE)</author><guid>https://www.poloxue.com/docs/gofyne/07-binding/03-conversion/</guid><description>&lt;p&gt;到目前为止，我们使用的数据绑定是数据类型与输出类型匹配的情况（例如&lt;code&gt;String&lt;/code&gt;与&lt;code&gt;Label&lt;/code&gt;或&lt;code&gt;Entry&lt;/code&gt;）。通常，将需要以不同于原始格式的方式展示数据。为此，&lt;code&gt;binding&lt;/code&gt;包提供了许多有用的转换函数。&lt;/p&gt;</description></item><item><title>列表类型</title><link>https://www.poloxue.com/docs/gofyne/07-binding/04-list/</link><pubDate>Mon, 14 Apr 2025 00:00:00 +0000</pubDate><author>poloxue123@gmail.com (POLO XUE)</author><guid>https://www.poloxue.com/docs/gofyne/07-binding/04-list/</guid><description>&lt;p&gt;为了展示如何连接更复杂的类型，我们将看看&lt;code&gt;List&lt;/code&gt;控件以及数据绑定如何使其更易用。首先，我们创建一个&lt;code&gt;StringList&lt;/code&gt;数据绑定，这是一个&lt;code&gt;String&lt;/code&gt;数据类型的列表。一旦我们有了列表类型的数据，我们就可以将这个数据连接到标准的&lt;code&gt;List&lt;/code&gt;控件。为此，我们使用&lt;code&gt;widget.NewListWithData&lt;/code&gt;构造函数，这和其他控件类似。&lt;/p&gt;</description></item></channel></rss>